gdb cleanups and tcg plugin register access
The following changes since commit 977542ded7e6b28d2bc077bcda24568c716e393c:
Merge tag 'pull-testing-updates-120124-2' of https://gitlab.com/stsquad/qemu into staging (2024-01-12 14:02:53 +0000)
are available in the Git repository at:
https://gitlab.com/stsquad/qemu.git tags/pull-registers-for-plugins-160124-2
for you to fetch changes up to 87bed6910aa0d0942244b5eedee60b4f8b162c05:
docs/devel: document some plugin assumptions (2024-01-16 10:34:20 +0000)
----------------------------------------------------------------
read-only register access for plugins:
- move misa_mxl to CPU class for riscv
- use GDBFeature for arm XML
- use GDBFeature for ppc XML
- use GDBFeature for riscv XML
- unify gdb code to use GDBFeature
- move dynamic XML generation to core GDB code
- provide introspection APIs for rest of QEMU
- expose a plugin API to access registers
- fix memory re-use in execlog
- extend execlog to track registers
- optimise instrumentation based on disassembly
- tweak API docs and expand on assumptions
----------------------------------------------------------------
Akihiko Odaki (15):
hw/riscv: Use misa_mxl instead of misa_mxl_max target/riscv: Remove misa_mxl validation target/riscv: Move misa_mxl_max to class target/riscv: Validate misa_mxl_max only once 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
plugins: Use different helpers when reading registers
Alex Bennée (7):
gdbstub: expose api to find registers
plugins: add an API to read registers contrib/plugins: fix imatch
contrib/plugins: extend execlog to track register changes contrib/plugins: optimise the register value tracking docs/devel: lift example and plugin API sections up docs/devel: document some plugin assumptions
docs/devel/tcg-plugins.rst | 72 +++++++++- accel/tcg/plugin-helpers.h | 3 +- include/exec/gdbstub.h | 62 ++++++++- include/hw/core/cpu.h | 7 +- include/qemu/plugin.h | 1 + include/qemu/qemu-plugin.h | 51 ++++++- 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 | 1 + target/ppc/cpu.h | 5 +- target/riscv/cpu.h | 9 +- target/s390x/cpu.h | 2 - accel/tcg/plugin-gen.c | 43 +++++- contrib/plugins/execlog.c | 324 ++++++++++++++++++++++++++++++++++++------- gdbstub/gdbstub.c | 198 +++++++++++++++++--------- hw/core/cpu-common.c | 5 +- hw/riscv/boot.c | 2 +- plugins/api.c | 123 +++++++++++++++- target/arm/cpu.c | 2 - target/arm/cpu64.c | 1 - target/arm/gdbstub.c | 230 +++++++++++++++--------------- target/arm/gdbstub64.c | 122 ++++++++-------- 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 | 7 - target/ppc/gdbstub.c | 114 +++++++-------- target/riscv/cpu.c | 193 +++++++++++++------------- target/riscv/gdbstub.c | 151 +++++++++++--------- target/riscv/kvm/kvm-cpu.c | 10 +- target/riscv/machine.c | 7 +- target/riscv/tcg/tcg-cpu.c | 44 +----- target/riscv/translate.c | 3 +- target/rx/cpu.c | 1 - target/s390x/cpu.c | 1 - target/s390x/gdbstub.c | 105 ++++++++------ plugins/qemu-plugins.symbols | 2 + scripts/feature_to_c.py | 14 +- 47 files changed, 1343 insertions(+), 695 deletions(-)
Signature · 1 line
2.39.2
[PULL 05/22] target/arm: Use GDBFeature for dynamic XML
From: Akihiko Odaki <[email protected]>
In preparation for a change to use GDBFeature as a parameter of gdb_register_coprocessor(), convert the internal representation of dynamic feature from plain XML to GDBFeature.
Message-Id: <[email protected]>
Message-Id: <[email protected]>
target/arm/cpu.h +10 -11
@@ -25,6 +25,7 @@#include "hw/registerfields.h" #include "cpu-qom.h" #include "exec/cpu-defs.h" +#include "exec/gdbstub.h" #include "qapi/qapi-types-common.h" /* ARM processors have a weak memory model */
@@ -136,23 +137,21 @@ enum {*/ /** -* DynamicGDBXMLInfo: -* @desc: Contains the XML descriptions. -* @num: Number of the registers in this XML seen by GDB. +* DynamicGDBFeatureInfo: +* @desc: Contains the feature descriptions. * @data: A union with data specific to the set of registers * @cpregs_keys: Array that contains the corresponding Key of * a given cpreg with the same order of the cpreg * in the XML description. */ -typedef struct DynamicGDBXMLInfo { -char *desc; -int num; +typedef struct DynamicGDBFeatureInfo { +GDBFeature desc;union {struct {uint32_t *keys; } cpregs; } data; -}DynamicGDBXMLInfo ; +}DynamicGDBFeatureInfo ;/* CPU state for each instance of a generic timer (in cp15 c14) */ typedef struct ARMGenericTimer {
@@ -881,10 +880,10 @@ struct ArchCPU {uint64_t *cpreg_vmstate_values;int32_t cpreg_vmstate_array_len; -DynamicGDBXMLInfo dyn_sysreg_xml; -DynamicGDBXMLInfo dyn_svereg_xml; -DynamicGDBXMLInfo dyn_m_systemreg_xml; -DynamicGDBXMLInfo dyn_m_secextreg_xml; +DynamicGDBFeatureInfo dyn_sysreg_feature; +DynamicGDBFeatureInfo dyn_svereg_feature; +DynamicGDBFeatureInfo dyn_m_systemreg_feature; +DynamicGDBFeatureInfo dyn_m_secextreg_feature;/* Timers used by the generic (architected) timer */ QEMUTimer *gt_timer[NUM_GTIMERS ];
target/arm/internals.h +1 -1
@@ -1446,7 +1446,7 @@ static inline uint64_t pmu_counter_mask(CPUARMState *env) }#ifdef TARGET_AARCH64 -int arm_gen_dynamic_svereg_xml (CPUState *cpu,int base_reg); +GDBFeature *arm_gen_dynamic_svereg_feature (CPUState *cpu,int base_reg);int aarch64_gdb_get_sve_reg (CPUARMState *env,GByteArray *buf,int reg);int aarch64_gdb_set_sve_reg (CPUARMState *env,uint8_t *buf,int reg);int aarch64_gdb_get_fpu_reg (CPUARMState *env,GByteArray *buf,int reg);
target/arm/gdbstub.c +69 -73
256 lines not on this page · raw message
target/arm/gdbstub64.c +43 -52
146 lines not on this page · raw message
Signature · 1 line
2.39.2
[PULL 08/22] gdbstub: Use GDBFeature for gdb_register_coprocessor
In reply to Alex BennéeFrom: Akihiko Odaki <[email protected]>
This is a tree-wide change to introduce GDBFeature parameter to gdb_register_coprocessor(). The new parameter just replaces num_regs and xml parameters for now. GDBFeature will be utilized to simplify XML lookup in a following change.
Message-Id: <[email protected]>
Message-Id: <[email protected]>
include/exec/gdbstub.h +1 -1
@@ -38,7 +38,7 @@ typedef int (*gdb_set_reg_cb)(CPUArchState *env, uint8_t *buf, int reg);*/ void gdb_register_coprocessor (CPUState *cpu,gdb_get_reg_cb get_reg,gdb_set_reg_cb set_reg, -int num_regs,const char *xml,int g_pos); +const GDBFeature *feature,int g_pos);/** * gdbserver_start: start the gdb server
gdbstub/gdbstub.c +7 -6
@@ -544,7 +544,7 @@ static int gdb_write_register(CPUState *cpu, uint8_t *mem_buf, int reg)void gdb_register_coprocessor (CPUState *cpu,gdb_get_reg_cb get_reg,gdb_set_reg_cb set_reg, -int num_regs,const char *xml,int g_pos) +const GDBFeature *feature,int g_pos) {GDBRegisterState *s;guint i;
@@ -553,7 +553,7 @@ void gdb_register_coprocessor(CPUState *cpu,for (i =0 ; i < cpu->gdb_regs->len; i++) {/* Check for duplicates. */ s = &g_array_index (cpu->gdb_regs, GDBRegisterState, i); -if (strcmp (s->xml, xml) ==0 ) { +if (strcmp (s->xml, feature->xmlname) ==0 ) {return ; } }
@@ -565,17 +565,18 @@ void gdb_register_coprocessor(CPUState *cpu,g_array_set_size (cpu->gdb_regs, i +1 ); s = &g_array_index (cpu->gdb_regs, GDBRegisterState, i); s->base_reg = cpu->gdb_num_regs; - s->num_regs = num_regs; + s->num_regs = feature->num_regs; s->get_reg = get_reg; s->set_reg = set_reg; - s->xml = xml; + s->xml = feature->xml;/* Add to end of list. */ - cpu->gdb_num_regs += num_regs; + cpu->gdb_num_regs += feature->num_regs;if (g_pos) {if (g_pos != s->base_reg) {error_report ("Error: Bad gdb register numbering for '%s', " -"expected %d got %d" , xml, g_pos, s->base_reg); +"expected %d got %d" , feature->xml, + g_pos, s->base_reg); }else { cpu->gdb_num_g_regs = cpu->gdb_num_regs; }
target/arm/gdbstub.c +19 -16
@@ -483,14 +483,14 @@ void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu)*/ #ifdef TARGET_AARCH64 if (isar_feature_aa64_sve (&cpu->isar)) { -int nreg =arm_gen_dynamic_svereg_feature (cs, cs->gdb_num_regs)->num_regs; +GDBFeature *feature =arm_gen_dynamic_svereg_feature (cs, cs->gdb_num_regs);gdb_register_coprocessor (cs, aarch64_gdb_get_sve_reg, - aarch64_gdb_set_sve_reg, nreg, -"sve-registers.xml" ,0 ); + aarch64_gdb_set_sve_reg, feature,0 ); }else {gdb_register_coprocessor (cs, aarch64_gdb_get_fpu_reg, aarch64_gdb_set_fpu_reg, -34 ,"aarch64-fpu.xml" ,0 ); +gdb_find_static_feature ("aarch64-fpu.xml" ), +0 ); }/* * Note that we report pauth information via the feature name
@@ -501,19 +501,22 @@ void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu)if (isar_feature_aa64_pauth (&cpu->isar)) {gdb_register_coprocessor (cs, aarch64_gdb_get_pauth_reg, aarch64_gdb_set_pauth_reg, -4 ,"aarch64-pauth.xml" ,0 ); +gdb_find_static_feature ("aarch64-pauth.xml" ), +0 ); }#endif }else {if (arm_feature (env,ARM_FEATURE_NEON )) {gdb_register_coprocessor (cs, vfp_gdb_get_reg, vfp_gdb_set_reg, -49 ,"arm-neon.xml" ,0 ); +gdb_find_static_feature ("arm-neon.xml" ), +0 ); }else if (cpu_isar_feature (aa32_simd_r32, cpu)) {gdb_register_coprocessor (cs, vfp_gdb_get_reg, vfp_gdb_set_reg, -33 ,"arm-vfp3.xml" ,0 ); +gdb_find_static_feature ("arm-vfp3.xml" ), +0 ); }else if (cpu_isar_feature (aa32_vfp_simd, cpu)) {gdb_register_coprocessor (cs, vfp_gdb_get_reg, vfp_gdb_set_reg, -17 ,"arm-vfp.xml" ,0 ); +gdb_find_static_feature ("arm-vfp.xml" ),0 ); }if (!arm_feature (env,ARM_FEATURE_M )) {/*
@@ -521,29 +524,29 @@ void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu)* expose to gdb. */ gdb_register_coprocessor (cs, vfp_gdb_get_sysreg, vfp_gdb_set_sysreg, -2 ,"arm-vfp-sysregs.xml" ,0 ); +gdb_find_static_feature ("arm-vfp-sysregs.xml" ), +0 ); } }if (cpu_isar_feature (aa32_mve, cpu) &&tcg_enabled ()) {gdb_register_coprocessor (cs, mve_gdb_get_reg, mve_gdb_set_reg, -1 ,"arm-m-profile-mve.xml" ,0 ); +gdb_find_static_feature ("arm-m-profile-mve.xml" ), +0 ); }gdb_register_coprocessor (cs, arm_gdb_get_sysreg, arm_gdb_set_sysreg, -arm_gen_dynamic_sysreg_feature (cs, cs->gdb_num_regs)->num_regs, -"system-registers.xml" ,0 ); +arm_gen_dynamic_sysreg_feature (cs, cs->gdb_num_regs), +0 );#ifdef CONFIG_TCG if (arm_feature (env,ARM_FEATURE_M ) &&tcg_enabled ()) {gdb_register_coprocessor (cs, arm_gdb_get_m_systemreg, arm_gdb_set_m_systemreg, -arm_gen_dynamic_m_systemreg_feature (cs, cs->gdb_num_regs)->num_regs, -"arm-m-system.xml" ,0 ); +arm_gen_dynamic_m_systemreg_feature (cs, cs->gdb_num_regs),0 );#ifndef CONFIG_USER_ONLY if (arm_feature (env,ARM_FEATURE_M_SECURITY )) {gdb_register_coprocessor (cs, arm_gdb_get_m_secextreg, arm_gdb_set_m_secextreg, -arm_gen_dynamic_m_secextreg_feature (cs, cs->gdb_num_regs)->num_regs, -"arm-m-secext.xml" ,0 ); +arm_gen_dynamic_m_secextreg_feature (cs, cs->gdb_num_regs),0 ); }#endif }
target/hexagon/cpu.c +1 -2
@@ -319,8 +319,7 @@ static void hexagon_cpu_realize(DeviceState *dev, Error **errp)gdb_register_coprocessor (cs, hexagon_hvx_gdb_read_register, hexagon_hvx_gdb_write_register, -NUM_VREGS +NUM_QREGS , -"hexagon-hvx.xml" ,0 ); +gdb_find_static_feature ("hexagon-hvx.xml" ),0 );qemu_init_vcpu (cs);cpu_reset (cs);
target/loongarch/gdbstub.c +1 -1
@@ -118,5 +118,5 @@ static int loongarch_gdb_set_fpu(CPULoongArchState *env,void loongarch_cpu_register_gdb_regs_for_features (CPUState *cs) {gdb_register_coprocessor (cs, loongarch_gdb_get_fpu, loongarch_gdb_set_fpu, -41 ,"loongarch-fpu.xml" ,0 ); +gdb_find_static_feature ("loongarch-fpu.xml" ),0 ); }
target/m68k/helper.c +3 -3
@@ -112,10 +112,10 @@ void m68k_cpu_init_gdb(M68kCPU *cpu)if (m68k_feature (env,M68K_FEATURE_CF_FPU )) {gdb_register_coprocessor (cs, cf_fpu_gdb_get_reg, cf_fpu_gdb_set_reg, -11 ,"cf-fp.xml" ,18 ); +gdb_find_static_feature ("cf-fp.xml" ),18 ); }else if (m68k_feature (env,M68K_FEATURE_FPU )) { -gdb_register_coprocessor (cs, m68k_fpu_gdb_get_reg, - m68k_fpu_gdb_set_reg,11 ,"m68k-fp.xml" ,18 ); +gdb_register_coprocessor (cs, m68k_fpu_gdb_get_reg, m68k_fpu_gdb_set_reg, +gdb_find_static_feature ("m68k-fp.xml" ),18 ); }/* TODO: Add [E]MAC registers. */ }
target/microblaze/cpu.c +3 -2
@@ -297,8 +297,9 @@ static void mb_cpu_initfn(Object *obj)CPUMBState *env = &cpu->env;gdb_register_coprocessor (CPU (cpu), mb_cpu_gdb_read_stack_protect, - mb_cpu_gdb_write_stack_protect,2 , -"microblaze-stack-protect.xml" ,0 ); + mb_cpu_gdb_write_stack_protect, +gdb_find_static_feature ("microblaze-stack-protect.xml" ), +0 );set_float_rounding_mode (float_round_nearest_even, &env->fp_status);
target/ppc/gdbstub.c +6 -5
@@ -570,23 +570,24 @@ void ppc_gdb_init(CPUState *cs, PowerPCCPUClass *pcc) {if (pcc->insns_flags &PPC_FLOAT ) {gdb_register_coprocessor (cs, gdb_get_float_reg, gdb_set_float_reg, -33 ,"power-fpu.xml" ,0 ); +gdb_find_static_feature ("power-fpu.xml" ),0 ); }if (pcc->insns_flags &PPC_ALTIVEC ) {gdb_register_coprocessor (cs, gdb_get_avr_reg, gdb_set_avr_reg, -34 ,"power-altivec.xml" ,0 ); +gdb_find_static_feature ("power-altivec.xml" ), +0 ); }if (pcc->insns_flags &PPC_SPE ) {gdb_register_coprocessor (cs, gdb_get_spe_reg, gdb_set_spe_reg, -34 ,"power-spe.xml" ,0 ); +gdb_find_static_feature ("power-spe.xml" ),0 ); }if (pcc->insns_flags2 &PPC2_VSX ) {gdb_register_coprocessor (cs, gdb_get_vsx_reg, gdb_set_vsx_reg, -32 ,"power-vsx.xml" ,0 ); +gdb_find_static_feature ("power-vsx.xml" ),0 ); }#ifndef CONFIG_USER_ONLY gdb_gen_spr_feature (cs);gdb_register_coprocessor (cs, gdb_get_spr_reg, gdb_set_spr_reg, - pcc->gdb_spr.num_regs,"power-spr.xml" ,0 ); + &pcc->gdb_spr,0 );#endif }
target/riscv/gdbstub.c +12 -8
@@ -311,28 +311,32 @@ void riscv_cpu_register_gdb_regs_for_features(CPUState *cs)CPURISCVState *env = &cpu->env;if (env->misa_ext &RVD ) {gdb_register_coprocessor (cs, riscv_gdb_get_fpu, riscv_gdb_set_fpu, -32 ,"riscv-64bit-fpu.xml" ,0 ); +gdb_find_static_feature ("riscv-64bit-fpu.xml" ), +0 ); }else if (env->misa_ext &RVF ) {gdb_register_coprocessor (cs, riscv_gdb_get_fpu, riscv_gdb_set_fpu, -32 ,"riscv-32bit-fpu.xml" ,0 ); +gdb_find_static_feature ("riscv-32bit-fpu.xml" ), +0 ); }if (env->misa_ext &RVV ) {gdb_register_coprocessor (cs, riscv_gdb_get_vector, riscv_gdb_set_vector, -ricsv_gen_dynamic_vector_feature (cs, cs->gdb_num_regs)->num_regs, -"riscv-vector.xml" ,0 ); +ricsv_gen_dynamic_vector_feature (cs, cs->gdb_num_regs), +0 ); }switch (mcc->misa_mxl_max) {case MXL_RV32 :gdb_register_coprocessor (cs, riscv_gdb_get_virtual, riscv_gdb_set_virtual, -1 ,"riscv-32bit-virtual.xml" ,0 ); +gdb_find_static_feature ("riscv-32bit-virtual.xml" ), +0 );break ;case MXL_RV64 :case MXL_RV128 :gdb_register_coprocessor (cs, riscv_gdb_get_virtual, riscv_gdb_set_virtual, -1 ,"riscv-64bit-virtual.xml" ,0 ); +gdb_find_static_feature ("riscv-64bit-virtual.xml" ), +0 );break ;default :g_assert_not_reached ();
@@ -340,7 +344,7 @@ void riscv_cpu_register_gdb_regs_for_features(CPUState *cs)if (cpu->cfg.ext_zicsr) {gdb_register_coprocessor (cs, riscv_gdb_get_csr, riscv_gdb_set_csr, -riscv_gen_dynamic_csr_feature (cs, cs->gdb_num_regs)->num_regs, -"riscv-csr.xml" ,0 ); +riscv_gen_dynamic_csr_feature (cs, cs->gdb_num_regs), +0 ); } }
target/s390x/gdbstub.c +7 -21
@@ -69,8 +69,6 @@ int s390_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)/* the values represent the positions in s390-acr.xml */ #define S390_A0_REGNUM 0#define S390_A15_REGNUM 15 -/* total number of registers in s390-acr.xml */ -#define S390_NUM_AC_REGS 16static int cpu_read_ac_reg (CPUS390XState *env,GByteArray *buf,int n) {
@@ -98,8 +96,6 @@ static int cpu_write_ac_reg(CPUS390XState *env, uint8_t *mem_buf, int n)#define S390_FPC_REGNUM 0#define S390_F0_REGNUM 1#define S390_F15_REGNUM 16 -/* total number of registers in s390-fpr.xml */ -#define S390_NUM_FP_REGS 17static int cpu_read_fp_reg (CPUS390XState *env,GByteArray *buf,int n) {
@@ -132,8 +128,6 @@ static int cpu_write_fp_reg(CPUS390XState *env, uint8_t *mem_buf, int n)#define S390_V15L_REGNUM 15#define S390_V16_REGNUM 16#define S390_V31_REGNUM 31 -/* total number of registers in s390-vx.xml */ -#define S390_NUM_VREGS 32static int cpu_read_vreg (CPUS390XState *env,GByteArray *buf,int n) {
@@ -172,8 +166,6 @@ static int cpu_write_vreg(CPUS390XState *env, uint8_t *mem_buf, int n)/* the values represent the positions in s390-cr.xml */ #define S390_C0_REGNUM 0#define S390_C15_REGNUM 15 -/* total number of registers in s390-cr.xml */ -#define S390_NUM_C_REGS 16#ifndef CONFIG_USER_ONLY static int cpu_read_c_reg (CPUS390XState *env,GByteArray *buf,int n)
@@ -206,8 +198,6 @@ static int cpu_write_c_reg(CPUS390XState *env, uint8_t *mem_buf, int n)#define S390_VIRT_CPUTM_REGNUM 1#define S390_VIRT_BEA_REGNUM 2#define S390_VIRT_PREFIX_REGNUM 3 -/* total number of registers in s390-virt.xml */ -#define S390_NUM_VIRT_REGS 4static int cpu_read_virt_reg (CPUS390XState *env,GByteArray *mem_buf,int n) {
@@ -254,8 +244,6 @@ static int cpu_write_virt_reg(CPUS390XState *env, uint8_t *mem_buf, int n)#define S390_VIRT_KVM_PFT_REGNUM 1#define S390_VIRT_KVM_PFS_REGNUM 2#define S390_VIRT_KVM_PFC_REGNUM 3 -/* total number of registers in s390-virt-kvm.xml */ -#define S390_NUM_VIRT_KVM_REGS 4static int cpu_read_virt_kvm_reg (CPUS390XState *env,GByteArray *mem_buf,int n) {
@@ -303,8 +291,6 @@ static int cpu_write_virt_kvm_reg(CPUS390XState *env, uint8_t *mem_buf, int n)#define S390_GS_GSD_REGNUM 1#define S390_GS_GSSM_REGNUM 2#define S390_GS_GSEPLA_REGNUM 3 -/* total number of registers in s390-gs.xml */ -#define S390_NUM_GS_REGS 4static int cpu_read_gs_reg (CPUS390XState *env,GByteArray *buf,int n) {
@@ -322,33 +308,33 @@ void s390_cpu_gdb_init(CPUState *cs) {gdb_register_coprocessor (cs, cpu_read_ac_reg, cpu_write_ac_reg, -S390_NUM_AC_REGS ,"s390-acr.xml" ,0 ); +gdb_find_static_feature ("s390-acr.xml" ),0 );gdb_register_coprocessor (cs, cpu_read_fp_reg, cpu_write_fp_reg, -S390_NUM_FP_REGS ,"s390-fpr.xml" ,0 ); +gdb_find_static_feature ("s390-fpr.xml" ),0 );gdb_register_coprocessor (cs, cpu_read_vreg, cpu_write_vreg, -S390_NUM_VREGS ,"s390-vx.xml" ,0 ); +gdb_find_static_feature ("s390-vx.xml" ),0 );gdb_register_coprocessor (cs, cpu_read_gs_reg, cpu_write_gs_reg, -S390_NUM_GS_REGS ,"s390-gs.xml" ,0 ); +gdb_find_static_feature ("s390-gs.xml" ),0 );#ifndef CONFIG_USER_ONLY gdb_register_coprocessor (cs, cpu_read_c_reg, cpu_write_c_reg, -S390_NUM_C_REGS ,"s390-cr.xml" ,0 ); +gdb_find_static_feature ("s390-cr.xml" ),0 );gdb_register_coprocessor (cs, cpu_read_virt_reg, cpu_write_virt_reg, -S390_NUM_VIRT_REGS ,"s390-virt.xml" ,0 ); +gdb_find_static_feature ("s390-virt.xml" ),0 );if (kvm_enabled ()) {gdb_register_coprocessor (cs, cpu_read_virt_kvm_reg, cpu_write_virt_kvm_reg, -S390_NUM_VIRT_KVM_REGS ,"s390-virt-kvm.xml" , +gdb_find_static_feature ("s390-virt-kvm.xml" ),0 ); }#endif
Signature · 1 line
2.39.2
[PULL 10/22] gdbstub: Change gdb_get_reg_cb and gdb_set_reg_cb
In reply to Alex BennéeFrom: Akihiko Odaki <[email protected]>
Align the parameters of gdb_get_reg_cb and gdb_set_reg_cb with the gdb_read_register and gdb_write_register members of CPUClass to allow to unify the logic to access registers of the core and coprocessors in the future.
Message-Id: <[email protected]>
Message-Id: <[email protected]>
include/exec/gdbstub.h +2 -2
@@ -24,8 +24,8 @@ typedef struct GDBFeatureBuilder {/* Get or set a register. Returns the size of the register. */ -typedef int (*gdb_get_reg_cb )(CPUArchState *env,GByteArray *buf,int reg); -typedef int (*gdb_set_reg_cb )(CPUArchState *env,uint8_t *buf,int reg); +typedef int (*gdb_get_reg_cb )(CPUState *cpu,GByteArray *buf,int reg); +typedef int (*gdb_set_reg_cb )(CPUState *cpu,uint8_t *buf,int reg);/** * gdb_register_coprocessor() - register a supplemental set of registers
target/arm/internals.h +6 -6
@@ -1447,12 +1447,12 @@ static inline uint64_t pmu_counter_mask(CPUARMState *env)#ifdef TARGET_AARCH64 GDBFeature *arm_gen_dynamic_svereg_feature (CPUState *cpu,int base_reg); -int aarch64_gdb_get_sve_reg (CPUARMState *env,GByteArray *buf,int reg); -int aarch64_gdb_set_sve_reg (CPUARMState *env,uint8_t *buf,int reg); -int aarch64_gdb_get_fpu_reg (CPUARMState *env,GByteArray *buf,int reg); -int aarch64_gdb_set_fpu_reg (CPUARMState *env,uint8_t *buf,int reg); -int aarch64_gdb_get_pauth_reg (CPUARMState *env,GByteArray *buf,int reg); -int aarch64_gdb_set_pauth_reg (CPUARMState *env,uint8_t *buf,int reg); +int aarch64_gdb_get_sve_reg (CPUState *cs,GByteArray *buf,int reg); +int aarch64_gdb_set_sve_reg (CPUState *cs,uint8_t *buf,int reg); +int aarch64_gdb_get_fpu_reg (CPUState *cs,GByteArray *buf,int reg); +int aarch64_gdb_set_fpu_reg (CPUState *cs,uint8_t *buf,int reg); +int aarch64_gdb_get_pauth_reg (CPUState *cs,GByteArray *buf,int reg); +int aarch64_gdb_set_pauth_reg (CPUState *cs,uint8_t *buf,int reg);void arm_cpu_sve_finalize (ARMCPU *cpu,Error **errp);void arm_cpu_sme_finalize (ARMCPU *cpu,Error **errp);void arm_cpu_pauth_finalize (ARMCPU *cpu,Error **errp);
target/hexagon/internal.h +2 -2
@@ -33,8 +33,8 @@int hexagon_gdb_read_register (CPUState *cpu,GByteArray *buf,int reg);int hexagon_gdb_write_register (CPUState *cpu,uint8_t *buf,int reg); -int hexagon_hvx_gdb_read_register (CPUHexagonState *env,GByteArray *mem_buf,int n); -int hexagon_hvx_gdb_write_register (CPUHexagonState *env,uint8_t *mem_buf,int n); +int hexagon_hvx_gdb_read_register (CPUState *env,GByteArray *mem_buf,int n); +int hexagon_hvx_gdb_write_register (CPUState *env,uint8_t *mem_buf,int n);void hexagon_debug_vreg (CPUHexagonState *env,int regnum);void hexagon_debug_qreg (CPUHexagonState *env,int regnum);
target/microblaze/cpu.h +2 -2
@@ -381,8 +381,8 @@ G_NORETURN void mb_cpu_do_unaligned_access(CPUState *cs, vaddr vaddr,void mb_cpu_dump_state (CPUState *cpu,FILE *f,int flags);int mb_cpu_gdb_read_register (CPUState *cpu,GByteArray *buf,int reg);int mb_cpu_gdb_write_register (CPUState *cpu,uint8_t *buf,int reg); -int mb_cpu_gdb_read_stack_protect (CPUArchState *cpu,GByteArray *buf,int reg); -int mb_cpu_gdb_write_stack_protect (CPUArchState *cpu,uint8_t *buf,int reg); +int mb_cpu_gdb_read_stack_protect (CPUState *cs,GByteArray *buf,int reg); +int mb_cpu_gdb_write_stack_protect (CPUState *cs,uint8_t *buf,int reg);static inline uint32_t mb_cpu_read_msr (const CPUMBState *env) {
gdbstub/gdbstub.c +2 -4
@@ -502,7 +502,6 @@ const GDBFeature *gdb_find_static_feature(const char *xmlname)static int gdb_read_register (CPUState *cpu,GByteArray *buf,int reg) {CPUClass *cc =CPU_GET_CLASS (cpu); -CPUArchState *env =cpu_env (cpu);GDBRegisterState *r;if (reg < cc->gdb_num_core_regs) {
@@ -513,7 +512,7 @@ static int gdb_read_register(CPUState *cpu, GByteArray *buf, int reg)for (guint i =0 ; i < cpu->gdb_regs->len; i++) { r = &g_array_index (cpu->gdb_regs, GDBRegisterState, i);if (r->base_reg <= reg && reg < r->base_reg + r->feature->num_regs) { -return r->get_reg (env, buf, reg - r->base_reg); +return r->get_reg (cpu, buf, reg - r->base_reg); } } }
@@ -523,7 +522,6 @@ static int gdb_read_register(CPUState *cpu, GByteArray *buf, int reg)static int gdb_write_register (CPUState *cpu,uint8_t *mem_buf,int reg) {CPUClass *cc =CPU_GET_CLASS (cpu); -CPUArchState *env =cpu_env (cpu);GDBRegisterState *r;if (reg < cc->gdb_num_core_regs) {
@@ -534,7 +532,7 @@ static int gdb_write_register(CPUState *cpu, uint8_t *mem_buf, int reg)for (guint i =0 ; i < cpu->gdb_regs->len; i++) { r = &g_array_index (cpu->gdb_regs, GDBRegisterState, i);if (r->base_reg <= reg && reg < r->base_reg + r->feature->num_regs) { -return r->set_reg (env, mem_buf, reg - r->base_reg); +return r->set_reg (cpu, mem_buf, reg - r->base_reg); } } }
target/arm/gdbstub.c +36 -15
129 lines not on this page · raw message
target/arm/gdbstub64.c +19 -8
@@ -72,8 +72,11 @@ int aarch64_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)return 0 ; } -int aarch64_gdb_get_fpu_reg (CPUARMState *env,GByteArray *buf,int reg) +int aarch64_gdb_get_fpu_reg (CPUState *cs,GByteArray *buf,int reg) { +ARMCPU *cpu =ARM_CPU (cs); +CPUARMState *env = &cpu->env; +switch (reg) { case 0 ... 31: {
@@ -92,8 +95,11 @@ int aarch64_gdb_get_fpu_reg(CPUARMState *env, GByteArray *buf, int reg) } } -int aarch64_gdb_set_fpu_reg (CPUARMState *env,uint8_t *buf,int reg) +int aarch64_gdb_set_fpu_reg (CPUState *cs,uint8_t *buf,int reg) { +ARMCPU *cpu =ARM_CPU (cs); +CPUARMState *env = &cpu->env; +switch (reg) { case 0 ... 31:/* 128 bit FP register */
@@ -116,9 +122,10 @@ int aarch64_gdb_set_fpu_reg(CPUARMState *env, uint8_t *buf, int reg) } } -int aarch64_gdb_get_sve_reg (CPUARMState *env,GByteArray *buf,int reg) +int aarch64_gdb_get_sve_reg (CPUState *cs,GByteArray *buf,int reg) { -ARMCPU *cpu =env_archcpu (env); +ARMCPU *cpu =ARM_CPU (cs); +CPUARMState *env = &cpu->env;switch (reg) {/* The first 32 registers are the zregs */
@@ -164,9 +171,10 @@ int aarch64_gdb_get_sve_reg(CPUARMState *env, GByteArray *buf, int reg)return 0 ; } -int aarch64_gdb_set_sve_reg (CPUARMState *env,uint8_t *buf,int reg) +int aarch64_gdb_set_sve_reg (CPUState *cs,uint8_t *buf,int reg) { -ARMCPU *cpu =env_archcpu (env); +ARMCPU *cpu =ARM_CPU (cs); +CPUARMState *env = &cpu->env;/* The first 32 registers are the zregs */ switch (reg) {
@@ -210,8 +218,11 @@ int aarch64_gdb_set_sve_reg(CPUARMState *env, uint8_t *buf, int reg)return 0 ; } -int aarch64_gdb_get_pauth_reg (CPUARMState *env,GByteArray *buf,int reg) +int aarch64_gdb_get_pauth_reg (CPUState *cs,GByteArray *buf,int reg) { +ARMCPU *cpu =ARM_CPU (cs); +CPUARMState *env = &cpu->env; +switch (reg) {case 0 :/* pauth_dmask */ case 1 :/* pauth_cmask */
@@ -241,7 +252,7 @@ int aarch64_gdb_get_pauth_reg(CPUARMState *env, GByteArray *buf, int reg) } } -int aarch64_gdb_set_pauth_reg (CPUARMState *env,uint8_t *buf,int reg) +int aarch64_gdb_set_pauth_reg (CPUState *cs,uint8_t *buf,int reg) {/* All pseudo registers are read-only. */ return 0 ;
target/hexagon/gdbstub.c +8 -2
@@ -81,8 +81,11 @@ static int gdb_get_qreg(CPUHexagonState *env, GByteArray *mem_buf, int n)return total; } -int hexagon_hvx_gdb_read_register (CPUHexagonState *env,GByteArray *mem_buf,int n) +int hexagon_hvx_gdb_read_register (CPUState *cs,GByteArray *mem_buf,int n) { +HexagonCPU *cpu =HEXAGON_CPU (cs); +CPUHexagonState *env = &cpu->env; +if (n <NUM_VREGS ) {return gdb_get_vreg (env, mem_buf, n); }
@@ -115,8 +118,11 @@ static int gdb_put_qreg(CPUHexagonState *env, uint8_t *mem_buf, int n)return MAX_VEC_SIZE_BYTES /8 ; } -int hexagon_hvx_gdb_write_register (CPUHexagonState *env,uint8_t *mem_buf,int n) +int hexagon_hvx_gdb_write_register (CPUState *cs,uint8_t *mem_buf,int n) { +HexagonCPU *cpu =HEXAGON_CPU (cs); +CPUHexagonState *env = &cpu->env; +if (n <NUM_VREGS ) {return gdb_put_vreg (env, mem_buf, n); }
target/loongarch/gdbstub.c +7 -4
@@ -84,9 +84,11 @@ int loongarch_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)return length; } -static int loongarch_gdb_get_fpu (CPULoongArchState *env, -GByteArray *mem_buf,int n) +static int loongarch_gdb_get_fpu (CPUState *cs,GByteArray *mem_buf,int n) { +LoongArchCPU *cpu =LOONGARCH_CPU (cs); +CPULoongArchState *env = &cpu->env; +if (0 <= n && n <32 ) {return gdb_get_reg64 (mem_buf, env->fpr[n].vreg.D (0 )); }else if (32 <= n && n <40 ) {
@@ -97,9 +99,10 @@ static int loongarch_gdb_get_fpu(CPULoongArchState *env,return 0 ; } -static int loongarch_gdb_set_fpu (CPULoongArchState *env, -uint8_t *mem_buf,int n) +static int loongarch_gdb_set_fpu (CPUState *cs,uint8_t *mem_buf,int n) { +LoongArchCPU *cpu =LOONGARCH_CPU (cs); +CPULoongArchState *env = &cpu->env;int length =0 ;if (0 <= n && n <32 ) {
target/m68k/helper.c +16 -4
@@ -29,8 +29,11 @@#define SIGNBIT (1u << 31) -static int cf_fpu_gdb_get_reg (CPUM68KState *env,GByteArray *mem_buf,int n) +static int cf_fpu_gdb_get_reg (CPUState *cs,GByteArray *mem_buf,int n) { +M68kCPU *cpu =M68K_CPU (cs); +CPUM68KState *env = &cpu->env; +if (n <8 ) {float_status s;return gdb_get_reg64 (mem_buf,floatx80_to_float64 (env->fregs[n].d, &s));
@@ -46,8 +49,11 @@ static int cf_fpu_gdb_get_reg(CPUM68KState *env, GByteArray *mem_buf, int n)return 0 ; } -static int cf_fpu_gdb_set_reg (CPUM68KState *env,uint8_t *mem_buf,int n) +static int cf_fpu_gdb_set_reg (CPUState *cs,uint8_t *mem_buf,int n) { +M68kCPU *cpu =M68K_CPU (cs); +CPUM68KState *env = &cpu->env; +if (n <8 ) {float_status s; env->fregs[n].d =float64_to_floatx80 (ldq_p (mem_buf), &s);
@@ -66,8 +72,11 @@ static int cf_fpu_gdb_set_reg(CPUM68KState *env, uint8_t *mem_buf, int n)return 0 ; } -static int m68k_fpu_gdb_get_reg (CPUM68KState *env,GByteArray *mem_buf,int n) +static int m68k_fpu_gdb_get_reg (CPUState *cs,GByteArray *mem_buf,int n) { +M68kCPU *cpu =M68K_CPU (cs); +CPUM68KState *env = &cpu->env; +if (n <8 ) {int len =gdb_get_reg16 (mem_buf, env->fregs[n].l.upper); len +=gdb_get_reg16 (mem_buf,0 );
@@ -85,8 +94,11 @@ static int m68k_fpu_gdb_get_reg(CPUM68KState *env, GByteArray *mem_buf, int n)return 0 ; } -static int m68k_fpu_gdb_set_reg (CPUM68KState *env,uint8_t *mem_buf,int n) +static int m68k_fpu_gdb_set_reg (CPUState *cs,uint8_t *mem_buf,int n) { +M68kCPU *cpu =M68K_CPU (cs); +CPUM68KState *env = &cpu->env; +if (n <8 ) { env->fregs[n].l.upper =lduw_be_p (mem_buf); env->fregs[n].l.lower =ldq_be_p (mem_buf +4 );
target/microblaze/gdbstub.c +7 -2
@@ -94,8 +94,10 @@ int mb_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)return gdb_get_reg32 (mem_buf, val); } -int mb_cpu_gdb_read_stack_protect (CPUMBState *env,GByteArray *mem_buf,int n) +int mb_cpu_gdb_read_stack_protect (CPUState *cs,GByteArray *mem_buf,int n) { +MicroBlazeCPU *cpu =MICROBLAZE_CPU (cs); +CPUMBState *env = &cpu->env;uint32_t val;switch (n) {
@@ -153,8 +155,11 @@ int mb_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)return 4 ; } -int mb_cpu_gdb_write_stack_protect (CPUMBState *env,uint8_t *mem_buf,int n) +int mb_cpu_gdb_write_stack_protect (CPUState *cs,uint8_t *mem_buf,int n) { +MicroBlazeCPU *cpu =MICROBLAZE_CPU (cs); +CPUMBState *env = &cpu->env; +switch (n) {case GDB_SP_SHL : env->slr =ldl_p (mem_buf);
target/ppc/gdbstub.c +36 -10
116 lines not on this page · raw message
target/riscv/gdbstub.c +34 -12
107 lines not on this page · raw message
target/s390x/gdbstub.c +59 -18
184 lines not on this page · raw message
Signature · 1 line
2.39.2
[PULL 12/22] gdbstub: Infer number of core registers from XML
In reply to Alex BennéeFrom: Akihiko Odaki <[email protected]>
GDBFeature has the num_regs member so use it where applicable to remove magic numbers.
Message-Id: <[email protected]>
Message-Id: <[email protected]>
include/hw/core/cpu.h +2 -1
@@ -127,7 +127,8 @@ struct SysemuCPUOps;* @gdb_adjust_breakpoint: Callback for adjusting the address of a * breakpoint. Used by AVR to handle a gdb mis-feature with * its Harvard architecture split code and data. -* @gdb_num_core_regs: Number of core registers accessible to GDB. +* @gdb_num_core_regs: Number of core registers accessible to GDB or 0 to infer +* from @gdb_core_xml_file. * @gdb_core_xml_file: File name for core registers GDB XML description. * @gdb_stop_before_watchpoint: Indicates whether GDB expects the CPU to stop * before the insn which triggers a watchpoint rather than after it.
target/s390x/cpu.h +0 -2
@@ -491,8 +491,6 @@ static inline void cpu_get_tb_cpu_state(CPUS390XState *env, vaddr *pc,#define S390_R13_REGNUM 15#define S390_R14_REGNUM 16#define S390_R15_REGNUM 17 -/* Total Core Registers. */ -#define S390_NUM_CORE_REGS 18static inline void setcc (S390CPU *cpu,uint64_t cc) {
gdbstub/gdbstub.c +4 -1
@@ -546,9 +546,12 @@ void gdb_init_cpu(CPUState *cpu)gdb_register_feature (cpu,0 , cc->gdb_read_register, cc->gdb_write_register, feature); + cpu->gdb_num_regs = cpu->gdb_num_g_regs = feature->num_regs; } - cpu->gdb_num_regs = cpu->gdb_num_g_regs = cc->gdb_num_core_regs; +if (cc->gdb_num_core_regs) { + cpu->gdb_num_regs = cpu->gdb_num_g_regs = cc->gdb_num_core_regs; + } } void gdb_register_coprocessor(CPUState *cpu,
target/arm/cpu.c +0 -1
@@ -2498,7 +2498,6 @@ static void arm_cpu_class_init(ObjectClass *oc, void *data)#ifndef CONFIG_USER_ONLY cc->sysemu_ops = &arm_sysemu_ops;#endif - cc->gdb_num_core_regs =26 ; cc->gdb_arch_name = arm_gdb_arch_name; cc->gdb_get_dynamic_xml = arm_gdb_get_dynamic_xml; cc->gdb_stop_before_watchpoint = true;
target/arm/cpu64.c +0 -1
@@ -793,7 +793,6 @@ static void aarch64_cpu_class_init(ObjectClass *oc, void *data) cc->gdb_read_register = aarch64_cpu_gdb_read_register; cc->gdb_write_register = aarch64_cpu_gdb_write_register; - cc->gdb_num_core_regs =34 ; cc->gdb_core_xml_file ="aarch64-core.xml" ; cc->gdb_arch_name = aarch64_gdb_arch_name;
target/avr/cpu.c +0 -1
@@ -245,7 +245,6 @@ static void avr_cpu_class_init(ObjectClass *oc, void *data) cc->gdb_read_register = avr_cpu_gdb_read_register; cc->gdb_write_register = avr_cpu_gdb_write_register; cc->gdb_adjust_breakpoint = avr_cpu_gdb_adjust_breakpoint; - cc->gdb_num_core_regs =35 ; cc->gdb_core_xml_file ="avr-cpu.xml" ; cc->tcg_ops = &avr_tcg_ops; }
target/hexagon/cpu.c +0 -1
@@ -362,7 +362,6 @@ static void hexagon_cpu_class_init(ObjectClass *c, void *data) cc->get_pc = hexagon_cpu_get_pc; cc->gdb_read_register = hexagon_gdb_read_register; cc->gdb_write_register = hexagon_gdb_write_register; - cc->gdb_num_core_regs =TOTAL_PER_THREAD_REGS ; cc->gdb_stop_before_watchpoint = true; cc->gdb_core_xml_file ="hexagon-core.xml" ; cc->disas_set_info = hexagon_cpu_disas_set_info;
target/i386/cpu.c +0 -2
@@ -7968,10 +7968,8 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data) cc->gdb_arch_name = x86_gdb_arch_name;#ifdef TARGET_X86_64 cc->gdb_core_xml_file ="i386-64bit.xml" ; - cc->gdb_num_core_regs =66 ;#else cc->gdb_core_xml_file ="i386-32bit.xml" ; - cc->gdb_num_core_regs =50 ;#endif cc->disas_set_info = x86_disas_set_info;
target/loongarch/cpu.c +0 -2
@@ -806,7 +806,6 @@ static void loongarch32_cpu_class_init(ObjectClass *c, void *data) {CPUClass *cc =CPU_CLASS (c); - cc->gdb_num_core_regs =35 ; cc->gdb_core_xml_file ="loongarch-base32.xml" ; cc->gdb_arch_name = loongarch32_gdb_arch_name; }
@@ -820,7 +819,6 @@ static void loongarch64_cpu_class_init(ObjectClass *c, void *data) {CPUClass *cc =CPU_CLASS (c); - cc->gdb_num_core_regs =35 ; cc->gdb_core_xml_file ="loongarch-base64.xml" ; cc->gdb_arch_name = loongarch64_gdb_arch_name; }
target/m68k/cpu.c +0 -1
@@ -562,7 +562,6 @@ static void m68k_cpu_class_init(ObjectClass *c, void *data)#endif cc->disas_set_info = m68k_cpu_disas_set_info; - cc->gdb_num_core_regs =18 ; cc->tcg_ops = &m68k_tcg_ops; }
target/microblaze/cpu.c +0 -1
@@ -428,7 +428,6 @@ static void mb_cpu_class_init(ObjectClass *oc, void *data) cc->sysemu_ops = &mb_sysemu_ops;#endif device_class_set_props (dc, mb_properties); - cc->gdb_num_core_regs =32 +25 ; cc->gdb_core_xml_file ="microblaze-core.xml" ; cc->disas_set_info = mb_disas_set_info;
target/riscv/cpu.c +0 -1
@@ -1826,7 +1826,6 @@ static void riscv_cpu_common_class_init(ObjectClass *c, void *data) cc->get_pc = riscv_cpu_get_pc; cc->gdb_read_register = riscv_cpu_gdb_read_register; cc->gdb_write_register = riscv_cpu_gdb_write_register; - cc->gdb_num_core_regs =33 ; cc->gdb_stop_before_watchpoint = true; cc->disas_set_info = riscv_cpu_disas_set_info;#ifndef CONFIG_USER_ONLY
target/rx/cpu.c +0 -1
@@ -215,7 +215,6 @@ static void rx_cpu_class_init(ObjectClass *klass, void *data) cc->gdb_write_register = rx_cpu_gdb_write_register; cc->disas_set_info = rx_cpu_disas_set_info; - cc->gdb_num_core_regs =26 ; cc->gdb_core_xml_file ="rx-core.xml" ; cc->tcg_ops = &rx_tcg_ops; }
target/s390x/cpu.c +0 -1
@@ -362,7 +362,6 @@ static void s390_cpu_class_init(ObjectClass *oc, void *data)s390_cpu_class_init_sysemu (cc);#endif cc->disas_set_info = s390_cpu_disas_set_info; - cc->gdb_num_core_regs =S390_NUM_CORE_REGS ; cc->gdb_core_xml_file ="s390x-core64.xml" ; cc->gdb_arch_name = s390_gdb_arch_name;
Signature · 1 line
2.39.2
[PULL 13/22] hw/core/cpu: Remove gdb_get_dynamic_xml member
In reply to Alex BennéeFrom: Akihiko Odaki <[email protected]>
This function is no longer used.
Message-Id: <[email protected]>
Message-Id: <[email protected]>
include/hw/core/cpu.h +0 -4
@@ -134,9 +134,6 @@ struct SysemuCPUOps;* before the insn which triggers a watchpoint rather than after it. * @gdb_arch_name: Optional callback that returns the architecture name known * to GDB. The caller must free the returned string with g_free. -* @gdb_get_dynamic_xml: Callback to return dynamically generated XML for the -* gdb stub. Returns a pointer to the XML contents for the specified XML file -* or NULL if the CPU doesn't have a dynamically generated content for it. * @disas_set_info: Setup architecture specific components of disassembly info * @adjust_watchpoint_address: Perform a target-specific adjustment to an * address before attempting to match it against watchpoints.
@@ -167,7 +164,6 @@ struct CPUClass {const char *gdb_core_xml_file;const gchar * (*gdb_arch_name)(CPUState *cpu); -const char * (*gdb_get_dynamic_xml)(CPUState *cpu,const char *xmlname);void (*disas_set_info)(CPUState *cpu,disassemble_info *info);
target/arm/cpu.h +0 -6
@@ -1185,12 +1185,6 @@ hwaddr arm_cpu_get_phys_page_attrs_debug(CPUState *cpu, vaddr addr,int arm_cpu_gdb_read_register (CPUState *cpu,GByteArray *buf,int reg);int arm_cpu_gdb_write_register (CPUState *cpu,uint8_t *buf,int reg); -/* Returns the dynamically generated XML for the gdb stub. -* Returns a pointer to the XML contents for the specified XML file or NULL -* if the XML name doesn't match the predefined one. -*/ -const char *arm_gdb_get_dynamic_xml (CPUState *cpu,const char *xmlname); -int arm_cpu_write_elf64_note (WriteCoreDumpFunction f,CPUState *cs,int cpuid,DumpState *s); int arm_cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cs,
target/ppc/cpu.h +0 -1
@@ -1524,7 +1524,6 @@ int ppc_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg);int ppc_cpu_gdb_write_register_apple (CPUState *cpu,uint8_t *buf,int reg);#ifndef CONFIG_USER_ONLY hwaddr ppc_cpu_get_phys_page_debug (CPUState *cpu,vaddr addr); -const char *ppc_gdb_get_dynamic_xml (CPUState *cs,const char *xml_name);#endif int ppc64_cpu_write_elf64_note (WriteCoreDumpFunction f,CPUState *cs,int cpuid,DumpState *s);
target/arm/cpu.c +0 -1
@@ -2499,7 +2499,6 @@ static void arm_cpu_class_init(ObjectClass *oc, void *data) cc->sysemu_ops = &arm_sysemu_ops;#endif cc->gdb_arch_name = arm_gdb_arch_name; - cc->gdb_get_dynamic_xml = arm_gdb_get_dynamic_xml; cc->gdb_stop_before_watchpoint = true; cc->disas_set_info = arm_disas_set_info;
target/arm/gdbstub.c +0 -18
@@ -474,24 +474,6 @@ static GDBFeature *arm_gen_dynamic_m_secextreg_feature(CPUState *cs,#endif #endif /* CONFIG_TCG */ -const char *arm_gdb_get_dynamic_xml (CPUState *cs,const char *xmlname) -{ -ARMCPU *cpu =ARM_CPU (cs); - -if (strcmp (xmlname,"system-registers.xml" ) ==0 ) { -return cpu->dyn_sysreg_feature.desc.xml; - }else if (strcmp (xmlname,"sve-registers.xml" ) ==0 ) { -return cpu->dyn_svereg_feature.desc.xml; - }else if (strcmp (xmlname,"arm-m-system.xml" ) ==0 ) { -return cpu->dyn_m_systemreg_feature.desc.xml; -#ifndef CONFIG_USER_ONLY - }else if (strcmp (xmlname,"arm-m-secext.xml" ) ==0 ) { -return cpu->dyn_m_secextreg_feature.desc.xml; -#endif - } -return NULL ; -} -void arm_cpu_register_gdb_regs_for_features (ARMCPU *cpu) {CPUState *cs =CPU (cpu);
target/ppc/cpu_init.c +0 -3
@@ -7379,9 +7379,6 @@ static void ppc_cpu_class_init(ObjectClass *oc, void *data)#endif cc->gdb_num_core_regs =71 ; -#ifndef CONFIG_USER_ONLY - cc->gdb_get_dynamic_xml = ppc_gdb_get_dynamic_xml; -#endif #ifdef USE_APPLE_GDB cc->gdb_read_register = ppc_cpu_gdb_read_register_apple; cc->gdb_write_register = ppc_cpu_gdb_write_register_apple;
target/ppc/gdbstub.c +0 -10
@@ -342,16 +342,6 @@ static void gdb_gen_spr_feature(CPUState *cs) gdb_feature_builder_end(&builder); } - -const char *ppc_gdb_get_dynamic_xml (CPUState *cs,const char *xml_name) -{ -PowerPCCPUClass *pcc =POWERPC_CPU_GET_CLASS (cs); - -if (strcmp (xml_name,"power-spr.xml" ) ==0 ) { -return pcc->gdb_spr.xml; - } -return NULL ; -}#endif #if !defined(CONFIG_USER_ONLY )
target/riscv/cpu.c +0 -14
@@ -1667,19 +1667,6 @@ static const gchar *riscv_gdb_arch_name(CPUState *cs) } } -static const char *riscv_gdb_get_dynamic_xml (CPUState *cs,const char *xmlname) -{ -RISCVCPU *cpu =RISCV_CPU (cs); - -if (strcmp (xmlname,"riscv-csr.xml" ) ==0 ) { -return cpu->dyn_csr_feature.xml; - }else if (strcmp (xmlname,"riscv-vector.xml" ) ==0 ) { -return cpu->dyn_vreg_feature.xml; - } - -return NULL ; -} -#ifndef CONFIG_USER_ONLY static int64_t riscv_get_arch_id (CPUState *cs) {
@@ -1833,7 +1820,6 @@ static void riscv_cpu_common_class_init(ObjectClass *c, void *data) cc->get_arch_id = riscv_get_arch_id;#endif cc->gdb_arch_name = riscv_gdb_arch_name; - cc->gdb_get_dynamic_xml = riscv_gdb_get_dynamic_xml;object_class_property_add (c,"mvendorid" ,"uint32" , cpu_get_mvendorid, cpu_set_mvendorid,NULL ,NULL );
Signature · 1 line
2.39.2
[PULL 02/22] target/riscv: Remove misa_mxl validation
In reply to Alex BennéeFrom: Akihiko Odaki <[email protected]>
It is initialized with a simple assignment and there is little room for error. In fact, the validation is even more complex.
Message-Id: <[email protected]>
Message-Id: <[email protected]>
target/riscv/tcg/tcg-cpu.c +3 -12
@@ -268,7 +268,7 @@ static void riscv_cpu_validate_misa_priv(CPURISCVState *env, Error **errp) } } -static void riscv_cpu_validate_misa_mxl (RISCVCPU *cpu,Error **errp) +static void riscv_cpu_validate_misa_mxl (RISCVCPU *cpu) {RISCVCPUClass *mcc =RISCV_CPU_GET_CLASS (cpu);CPUClass *cc =CPU_CLASS (mcc);
@@ -288,11 +288,6 @@ static void riscv_cpu_validate_misa_mxl(RISCVCPU *cpu, Error **errp)default :g_assert_not_reached (); } - -if (env->misa_mxl_max != env->misa_mxl) { -error_setg (errp,"misa_mxl_max must be equal to misa_mxl" ); -return ; - } }static void riscv_cpu_validate_priv_spec (RISCVCPU *cpu,Error **errp)
@@ -932,7 +927,6 @@ static bool riscv_cpu_is_vendor(Object *cpu_obj)static bool tcg_cpu_realize (CPUState *cs,Error **errp) {RISCVCPU *cpu =RISCV_CPU (cs); -Error *local_err =NULL ;if (!riscv_cpu_tcg_compatible (cpu)) { g_autofree char *name = riscv_cpu_get_name(cpu);
@@ -941,14 +935,11 @@ static bool tcg_cpu_realize(CPUState *cs, Error **errp)return false; } -riscv_cpu_validate_misa_mxl (cpu, &local_err); -if (local_err !=NULL ) { -error_propagate (errp, local_err); -return false; - } +riscv_cpu_validate_misa_mxl (cpu);#ifndef CONFIG_USER_ONLY CPURISCVState *env = &cpu->env; +Error *local_err =NULL ;CPU (cs)->tcg_cflags |=CF_PCREL ;
Signature · 1 line
2.39.2
[PULL 01/22] hw/riscv: Use misa_mxl instead of misa_mxl_max
In reply to Alex BennéeFrom: Akihiko Odaki <[email protected]>
The effective MXL value matters when booting.
Message-Id: <[email protected]>
Message-Id: <[email protected]>
hw/riscv/boot.c +1 -1
@@ -36,7 +36,7 @@bool riscv_is_32bit (RISCVHartArrayState *harts) { -return harts->harts[0 ].env.misa_mxl_max ==MXL_RV32 ; +return harts->harts[0 ].env.misa_mxl ==MXL_RV32 ; }/*
Signature · 1 line
2.39.2
[PULL 16/22] gdbstub: expose api to find registers
In reply to Alex BennéeExpose an internal API to QEMU to return all the registers for a vCPU. The list containing the details required to called gdb_read_register().
Based-on: <[email protected]>
Cc: Akihiko Odaki <[email protected]>
Message-Id: <[email protected]>
include/exec/gdbstub.h +47 -0
@@ -111,6 +111,53 @@ void gdb_feature_builder_end(const GDBFeatureBuilder *builder);*/ const GDBFeature *gdb_find_static_feature (const char *xmlname); +/** +* gdb_find_feature() - Find a feature associated with a CPU. +* @cpu: The CPU associated with the feature. +* @name: The feature's name. +* +* Return: The feature's number. +*/ +int gdb_find_feature (CPUState *cpu,const char *name); + +/** +* gdb_find_feature_register() - Find a register associated with a CPU. +* @cpu: The CPU associated with the register. +* @feature: The feature's number returned by gdb_find_feature(). +* @name: The register's name. +* +* Return: The register's number. +*/ +int gdb_find_feature_register (CPUState *cpu,int feature,const char *name); + +/** +* gdb_read_register() - Read a register associated with a CPU. +* @cpu: The CPU associated with the register. +* @buf: The buffer that the read register will be appended to. +* @reg: The register's number returned by gdb_find_feature_register(). +* +* Return: The number of read bytes. +*/ +int gdb_read_register (CPUState *cpu,GByteArray *buf,int reg); + +/** +* typedef GDBRegDesc - a register description from gdbstub +*/ +typedef struct { +int gdb_reg; +const char *name; +const char *feature_name; +}GDBRegDesc ; + +/** +* gdb_get_register_list() - Return list of all registers for CPU +* @cpu: The CPU being searched +* +* Returns a GArray of GDBRegDesc, caller frees array but not the +* const strings. +*/ +GArray *gdb_get_register_list (CPUState *cpu); +void gdb_set_stop_cpu (CPUState *cpu);/* in gdbstub-xml.c, generated by scripts/feature_to_c.py */
gdbstub/gdbstub.c +55 -1
62 lines not on this page · raw message
Signature · 1 line
2.39.2
Re: [PULL 16/22] gdbstub: expose api to find registers
Quoted 7 lines · Alex Bennée
Expose an internal API to QEMU to return all the registers for a vCPU. The list containing the details required to called
gdb_read_register().Based-on: <[email protected]>
Cc: Akihiko Odaki <[email protected]>
Message-Id: <[email protected]>Signed-off-by Alex Bennée <[email protected]>
I'm not for to pull this, "[PULL 17/22] plugins: add an API to read registers", and "[PULL 19/22] contrib/plugins: extend execlog to track register changes" in the current state. I have only commented the API aspect of these patches, but looking at them now, I see something wrong with their implementations. I'll add comments to respective patches.
Quoted 7 lines
include/exec/gdbstub.h +0
-0@@ -111,6 +111,53 @@ void gdb_feature_builder_end(const GDBFeatureBuilder *builder);*/
include/exec/gdbstub.h void gdb_feature_builder_end(const GDBFeatureBuilder *builder); · line 121
Quoted 10 lines
include/exec/gdbstub.h +8
-0const GDBFeature *gdb_find_static_feature (const char *xmlname); +/** +* gdb_find_feature() - Find a feature associated with a CPU. +* @cpu: The CPU associated with the feature. +* @name: The feature's name. +* +* Return: The feature's number. +*/ +int gdb_find_feature (CPUState *cpu,const char *name);
This function is not used.
include/exec/gdbstub.h void gdb_feature_builder_end(const GDBFeatureBuilder *builder); · line 131
Quoted 10 lines
include/exec/gdbstub.h +10
-0+ +/** +* gdb_find_feature_register() - Find a register associated with a CPU. +* @cpu: The CPU associated with the register. +* @feature: The feature's number returned by gdb_find_feature(). +* @name: The register's name. +* +* Return: The register's number. +*/ +int gdb_find_feature_register (CPUState *cpu,int feature,const char *name);
This function is also no longer needed.
Regards,
Akihiko Odaki
Re: [PULL 16/22] gdbstub: expose api to find registers
Quoted 8 lines · Akihiko Odaki
Quoted 6 lines · Alex Bennée
Expose an internal API to QEMU to return all the registers for a vCPU. The list containing the details required to called
gdb_read_register().
Based-on: <[email protected]>
Cc: Akihiko Odaki <[email protected]>
Message-Id: <[email protected]>Signed-off-by Alex Bennée <[email protected]>
Quoted 6 lines
I'm not for to pull this, "[PULL 17/22] plugins: add an API to read registers", and "[PULL 19/22] contrib/plugins: extend execlog to track register changes" in the current state. I have only commented the API aspect of these patches, but looking at them now, I see something wrong with their implementations. I'll add comments to respective patches.
OK - the patches where on the list for 14 days so I was going to merge as is and fix up any issues after the fact. But if there is review incoming I can re-spin without the final series.
There is other plugin activity going on I'd like to get merged this cycle so I don't want to hold stuff up.
Quoted 19 lines
Quoted 6 lines
include/exec/gdbstub.h +0
-0include/exec/gdbstub.h void gdb_feature_builder_end(const GDBFeatureBuilder *builder); · line 120
Quoted 10 lines
include/exec/gdbstub.h +7
-0@@ -111,6 +111,53 @@ void gdb_feature_builder_end(const GDBFeatureBuilder *builder);*/ const GDBFeature *gdb_find_static_feature (const char *xmlname); +/** +* gdb_find_feature() - Find a feature associated with a CPU. +* @cpu: The CPU associated with the feature. +* @name: The feature's name. +* +* Return: The feature's number. +*/ +int gdb_find_feature(CPUState *cpu, const char *name);This function is not used.
Quoted 12 lines
include/exec/gdbstub.h void gdb_feature_builder_end(const GDBFeatureBuilder *builder); · line 131
Quoted 10 lines
include/exec/gdbstub.h +10
-0+ +/** +* gdb_find_feature_register() - Find a register associated with a CPU. +* @cpu: The CPU associated with the register. +* @feature: The feature's number returned by gdb_find_feature(). +* @name: The register's name. +* +* Return: The register's number. +*/ +int gdb_find_feature_register (CPUState *cpu,int feature,const char *name);This function is also no longer needed.
Ahh looks like a merge failure when I re-based.
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
[PULL 09/22] gdbstub: Use GDBFeature for GDBRegisterState
In reply to Alex BennéeFrom: Akihiko Odaki <[email protected]>
Simplify GDBRegisterState by replacing num_regs and xml members with one member that points to GDBFeature.
Message-Id: <[email protected]>
Message-Id: <[email protected]>
gdbstub/gdbstub.c +6 -8
@@ -47,10 +47,9 @@typedef struct GDBRegisterState {int base_reg; -int num_regs;gdb_get_reg_cb get_reg;gdb_set_reg_cb set_reg; -const char *xml; +const GDBFeature *feature; }GDBRegisterState ;GDBState gdbserver_state;
@@ -391,7 +390,7 @@ static const char *get_feature_xml(const char *p, const char **newp,g_ptr_array_add ( xml,g_markup_printf_escaped ("<xi:include href=\"%s\"/>" , - r->xml)); + r->feature->xmlname)); } }g_ptr_array_add (xml,g_strdup ("</target>" ));
@@ -513,7 +512,7 @@ static int gdb_read_register(CPUState *cpu, GByteArray *buf, int reg)if (cpu->gdb_regs) {for (guint i =0 ; i < cpu->gdb_regs->len; i++) { r = &g_array_index (cpu->gdb_regs, GDBRegisterState, i); -if (r->base_reg <= reg && reg < r->base_reg + r->num_regs) { +if (r->base_reg <= reg && reg < r->base_reg + r->feature->num_regs) {return r->get_reg (env, buf, reg - r->base_reg); } }
@@ -534,7 +533,7 @@ static int gdb_write_register(CPUState *cpu, uint8_t *mem_buf, int reg)if (cpu->gdb_regs) {for (guint i =0 ; i < cpu->gdb_regs->len; i++) { r = &g_array_index (cpu->gdb_regs, GDBRegisterState, i); -if (r->base_reg <= reg && reg < r->base_reg + r->num_regs) { +if (r->base_reg <= reg && reg < r->base_reg + r->feature->num_regs) {return r->set_reg (env, mem_buf, reg - r->base_reg); } }
@@ -553,7 +552,7 @@ void gdb_register_coprocessor(CPUState *cpu,for (i =0 ; i < cpu->gdb_regs->len; i++) {/* Check for duplicates. */ s = &g_array_index (cpu->gdb_regs, GDBRegisterState, i); -if (strcmp (s->xml, feature->xmlname) ==0 ) { +if (s->feature == feature) {return ; } }
@@ -565,10 +564,9 @@ void gdb_register_coprocessor(CPUState *cpu,g_array_set_size (cpu->gdb_regs, i +1 ); s = &g_array_index (cpu->gdb_regs, GDBRegisterState, i); s->base_reg = cpu->gdb_num_regs; - s->num_regs = feature->num_regs; s->get_reg = get_reg; s->set_reg = set_reg; - s->xml = feature->xml; + s->feature = feature;/* Add to end of list. */ cpu->gdb_num_regs += feature->num_regs;
Signature · 1 line
2.39.2
[PULL 06/22] target/ppc: Use GDBFeature for dynamic XML
In reply to Alex BennéeFrom: Akihiko Odaki <[email protected]>
In preparation for a change to use GDBFeature as a parameter of gdb_register_coprocessor(), convert the internal representation of dynamic feature from plain XML to GDBFeature.
Message-Id: <[email protected]>
Message-Id: <[email protected]>
target/ppc/cpu-qom.h +1 -0
@@ -20,6 +20,7 @@#ifndef QEMU_PPC_CPU_QOM_H #define QEMU_PPC_CPU_QOM_H +#include "exec/gdbstub.h" #include "hw/core/cpu.h" #ifdef TARGET_PPC64
target/ppc/cpu.h +1 -3
@@ -1471,8 +1471,7 @@ struct PowerPCCPUClass {int bfd_mach;uint32_t l1_dcache_size, l1_icache_size;#ifndef CONFIG_USER_ONLY -unsigned int gdb_num_sprs; -const char *gdb_spr_xml; +GDBFeature gdb_spr;#endif const PPCHash64Options *hash64_opts;struct ppc_radix_page_info *radix_page_info;
@@ -1525,7 +1524,6 @@ int ppc_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg);int ppc_cpu_gdb_write_register_apple (CPUState *cpu,uint8_t *buf,int reg);#ifndef CONFIG_USER_ONLY hwaddr ppc_cpu_get_phys_page_debug (CPUState *cpu,vaddr addr); -void ppc_gdb_gen_spr_xml (PowerPCCPU *cpu);const char *ppc_gdb_get_dynamic_xml (CPUState *cs,const char *xml_name);#endif int ppc64_cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cs,
target/ppc/cpu_init.c +0 -4
@@ -6682,10 +6682,6 @@ static void init_ppc_proc(PowerPCCPU *cpu)/* PowerPC implementation specific initialisations (SPRs, timers, ...) */ (*pcc->init_proc)(env); -#if !defined(CONFIG_USER_ONLY ) -ppc_gdb_gen_spr_xml (cpu); -#endif -/* MSR bits & flags consistency checks */ if (env->msr_mask & (1 <<25 )) {switch (env->flags & (POWERPC_FLAG_SPE |POWERPC_FLAG_VRE )) {
target/ppc/gdbstub.c +19 -32
83 lines not on this page · raw message
Signature · 1 line
2.39.2
[PULL 04/22] target/riscv: Validate misa_mxl_max only once
In reply to Alex BennéeFrom: Akihiko Odaki <[email protected]>
misa_mxl_max is now a class member and initialized only once for each class. This also moves the initialization of gdb_core_xml_file which will be referenced before realization in the future.
Message-Id: <[email protected]>
Message-Id: <[email protected]>
target/riscv/cpu.c +21 -0
@@ -1292,6 +1292,26 @@ static const MISAExtInfo misa_ext_info_arr[] = { MISA_EXT_INFO(RVG, "g", "General purpose (IMAFD_Zicsr_Zifencei)"), }; +static void riscv_cpu_validate_misa_mxl (RISCVCPUClass *mcc) +{ +CPUClass *cc =CPU_CLASS (mcc); + +/* Validate that MISA_MXL is set properly. */ +switch (mcc->misa_mxl_max) { +#ifdef TARGET_RISCV64 +case MXL_RV64 : +case MXL_RV128 : + cc->gdb_core_xml_file ="riscv-64bit-cpu.xml" ; +break ; +#endif +case MXL_RV32 : + cc->gdb_core_xml_file ="riscv-32bit-cpu.xml" ; +break ; +default : +g_assert_not_reached (); + } +} +static int riscv_validate_misa_info_idx (uint32_t bit) {int idx;
@@ -1833,6 +1853,7 @@ static void riscv_cpu_class_init(ObjectClass *c, void *data)RISCVCPUClass *mcc =RISCV_CPU_CLASS (c); mcc->misa_mxl_max = (uint32_t )(uintptr_t )data; +riscv_cpu_validate_misa_mxl (mcc); } static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str,
target/riscv/tcg/tcg-cpu.c +0 -23
@@ -268,27 +268,6 @@ static void riscv_cpu_validate_misa_priv(CPURISCVState *env, Error **errp) } } -static void riscv_cpu_validate_misa_mxl (RISCVCPU *cpu) -{ -RISCVCPUClass *mcc =RISCV_CPU_GET_CLASS (cpu); -CPUClass *cc =CPU_CLASS (mcc); - -/* Validate that MISA_MXL is set properly. */ -switch (mcc->misa_mxl_max) { -#ifdef TARGET_RISCV64 -case MXL_RV64 : -case MXL_RV128 : - cc->gdb_core_xml_file ="riscv-64bit-cpu.xml" ; -break ; -#endif -case MXL_RV32 : - cc->gdb_core_xml_file ="riscv-32bit-cpu.xml" ; -break ; -default : -g_assert_not_reached (); - } -} -static void riscv_cpu_validate_priv_spec (RISCVCPU *cpu,Error **errp) {CPURISCVState *env = &cpu->env;
@@ -935,8 +914,6 @@ static bool tcg_cpu_realize(CPUState *cs, Error **errp)return false; } -riscv_cpu_validate_misa_mxl (cpu); -#ifndef CONFIG_USER_ONLY CPURISCVState *env = &cpu->env;Error *local_err =NULL ;
Signature · 1 line
2.39.2
[PULL 07/22] target/riscv: Use GDBFeature for dynamic XML
In reply to Alex BennéeFrom: Akihiko Odaki <[email protected]>
In preparation for a change to use GDBFeature as a parameter of gdb_register_coprocessor(), convert the internal representation of dynamic feature from plain XML to GDBFeature.
Message-Id: <[email protected]>
Message-Id: <[email protected]>
target/riscv/cpu.h +3 -2
@@ -24,6 +24,7 @@#include "hw/registerfields.h" #include "hw/qdev-properties.h" #include "exec/cpu-defs.h" +#include "exec/gdbstub.h" #include "qemu/cpu-float.h" #include "qom/object.h" #include "qemu/int128.h"
@@ -440,8 +441,8 @@ struct ArchCPU {CPURISCVState env; -char *dyn_csr_xml; -char *dyn_vreg_xml; +GDBFeature dyn_csr_feature; +GDBFeature dyn_vreg_feature;/* Configuration Settings */ RISCVCPUConfig cfg;
target/riscv/cpu.c +2 -2
@@ -1672,9 +1672,9 @@ static const char *riscv_gdb_get_dynamic_xml(CPUState *cs, const char *xmlname)RISCVCPU *cpu =RISCV_CPU (cs);if (strcmp (xmlname,"riscv-csr.xml" ) ==0 ) { -return cpu->dyn_csr_xml; +return cpu->dyn_csr_feature.xml; }else if (strcmp (xmlname,"riscv-vector.xml" ) ==0 ) { -return cpu->dyn_vreg_xml; +return cpu->dyn_vreg_feature.xml; }return NULL ;
target/riscv/gdbstub.c +35 -44
148 lines not on this page · raw message
Signature · 1 line
2.39.2
[PULL 03/22] target/riscv: Move misa_mxl_max to class
In reply to Alex BennéeFrom: Akihiko Odaki <[email protected]>
misa_mxl_max is common for all instances of a RISC-V CPU class so they are better put into class.
Message-Id: <[email protected]>
Message-Id: <[email protected]>
target/riscv/cpu.h +2 -2
@@ -185,7 +185,6 @@ struct CPUArchState {/* RISCVMXL, but uint32_t for vmstate migration */ uint32_t misa_mxl;/* current mxl */ -uint32_t misa_mxl_max;/* max mxl for this cpu */ uint32_t misa_ext;/* current extensions */ uint32_t misa_ext_mask;/* max ext for this cpu */ uint32_t xl;/* current xlen */
@@ -466,6 +465,7 @@ struct RISCVCPUClass {DeviceRealize parent_realize;ResettablePhases parent_phases; +uint32_t misa_mxl_max;/* max mxl for this cpu */ };static inline int riscv_has_ext (CPURISCVState *env,target_ulong ext)
@@ -771,7 +771,7 @@ enum riscv_pmu_event_idx {/* used by tcg/tcg-cpu.c*/ void isa_ext_update_enabled (RISCVCPU *cpu,uint32_t ext_offset,bool en);bool isa_ext_is_enabled (RISCVCPU *cpu,uint32_t ext_offset); -void riscv_cpu_set_misa (CPURISCVState *env,RISCVMXL mxl,uint32_t ext); +void riscv_cpu_set_misa_ext (CPURISCVState *env,uint32_t ext); typedef struct RISCVCPUMultiExtConfig { const char *name;
target/riscv/cpu.c +79 -78
301 lines not on this page · raw message
target/riscv/gdbstub.c +8 -4
@@ -49,6 +49,7 @@ static const struct TypeSize vec_lanes[] = {int riscv_cpu_gdb_read_register (CPUState *cs,GByteArray *mem_buf,int n) { +RISCVCPUClass *mcc =RISCV_CPU_GET_CLASS (cs);RISCVCPU *cpu =RISCV_CPU (cs);CPURISCVState *env = &cpu->env;target_ulong tmp;
@@ -61,7 +62,7 @@ int riscv_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)return 0 ; } -switch (env->misa_mxl_max) { +switch (mcc->misa_mxl_max) {case MXL_RV32 :return gdb_get_reg32 (mem_buf, tmp);case MXL_RV64 :
@@ -75,12 +76,13 @@ int riscv_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)int riscv_cpu_gdb_write_register (CPUState *cs,uint8_t *mem_buf,int n) { +RISCVCPUClass *mcc =RISCV_CPU_GET_CLASS (cs);RISCVCPU *cpu =RISCV_CPU (cs);CPURISCVState *env = &cpu->env;int length =0 ;target_ulong tmp; -switch (env->misa_mxl_max) { +switch (mcc->misa_mxl_max) {case MXL_RV32 : tmp = (int32_t )ldl_p (mem_buf); length =4 ;
@@ -214,11 +216,12 @@ static int riscv_gdb_set_virtual(CPURISCVState *cs, uint8_t *mem_buf, int n)static int riscv_gen_dynamic_csr_xml (CPUState *cs,int base_reg) { +RISCVCPUClass *mcc =RISCV_CPU_GET_CLASS (cs);RISCVCPU *cpu =RISCV_CPU (cs);CPURISCVState *env = &cpu->env;GString *s =g_string_new (NULL );riscv_csr_predicate_fn predicate; -int bitsize =16 << env->misa_mxl_max; +int bitsize =16 << mcc->misa_mxl_max;int i;#if !defined(CONFIG_USER_ONLY )
@@ -310,6 +313,7 @@ static int ricsv_gen_dynamic_vector_xml(CPUState *cs, int base_reg)void riscv_cpu_register_gdb_regs_for_features (CPUState *cs) { +RISCVCPUClass *mcc =RISCV_CPU_GET_CLASS (cs);RISCVCPU *cpu =RISCV_CPU (cs);CPURISCVState *env = &cpu->env;if (env->misa_ext &RVD ) {
@@ -326,7 +330,7 @@ void riscv_cpu_register_gdb_regs_for_features(CPUState *cs)ricsv_gen_dynamic_vector_xml (cs, base_reg), "riscv-vector.xml", 0); } -switch (env->misa_mxl_max) { +switch (mcc->misa_mxl_max) {case MXL_RV32 : gdb_register_coprocessor(cs, riscv_gdb_get_virtual, riscv_gdb_set_virtual,
target/riscv/kvm/kvm-cpu.c +5 -5
@@ -1619,14 +1619,14 @@ static void kvm_cpu_accel_register_types(void) }type_init (kvm_cpu_accel_register_types); -static void riscv_host_cpu_init (Object *obj) +static void riscv_host_cpu_class_init (ObjectClass *c,void *data) { -CPURISCVState *env = &RISCV_CPU (obj)->env; +RISCVCPUClass *mcc =RISCV_CPU_CLASS (c);#if defined(TARGET_RISCV32 ) - env->misa_mxl_max = env->misa_mxl =MXL_RV32 ; + mcc->misa_mxl_max =MXL_RV32 ;#elif defined(TARGET_RISCV64 ) - env->misa_mxl_max = env->misa_mxl =MXL_RV64 ; + mcc->misa_mxl_max =MXL_RV64 ;#endif }
@@ -1634,7 +1634,7 @@ static const TypeInfo riscv_kvm_cpu_type_infos[] = { { .name = TYPE_RISCV_CPU_HOST, .parent = TYPE_RISCV_CPU, - .instance_init = riscv_host_cpu_init, + .class_init = riscv_host_cpu_class_init, } };
target/riscv/machine.c +3 -4
@@ -178,10 +178,9 @@ static const VMStateDescription vmstate_pointermasking = {static bool rv128_needed (void *opaque) { -RISCVCPU *cpu = opaque; -CPURISCVState *env = &cpu->env; +RISCVCPUClass *mcc =RISCV_CPU_GET_CLASS (opaque); -return env->misa_mxl_max ==MXL_RV128 ; +return mcc->misa_mxl_max ==MXL_RV128 ; }static const VMStateDescription vmstate_rv128 = {
@@ -372,7 +371,7 @@ const VMStateDescription vmstate_riscv_cpu = {VMSTATE_UINTTL (env.vext_ver,RISCVCPU ),VMSTATE_UINT32 (env.misa_mxl,RISCVCPU ),VMSTATE_UINT32 (env.misa_ext,RISCVCPU ), -VMSTATE_UINT32 (env.misa_mxl_max,RISCVCPU ), +VMSTATE_UNUSED (4 ),VMSTATE_UINT32 (env.misa_ext_mask,RISCVCPU ),VMSTATE_UINTTL (env.priv,RISCVCPU ), VMSTATE_BOOL(env.virt_enabled, RISCVCPU),
target/riscv/tcg/tcg-cpu.c +6 -6
@@ -272,10 +272,9 @@ static void riscv_cpu_validate_misa_mxl(RISCVCPU *cpu) {RISCVCPUClass *mcc =RISCV_CPU_GET_CLASS (cpu);CPUClass *cc =CPU_CLASS (mcc); -CPURISCVState *env = &cpu->env;/* Validate that MISA_MXL is set properly. */ -switch (env->misa_mxl_max) { +switch (mcc->misa_mxl_max) {#ifdef TARGET_RISCV64 case MXL_RV64 :case MXL_RV128 :
@@ -443,6 +442,7 @@ static void riscv_cpu_validate_g(RISCVCPU *cpu)*/ void riscv_cpu_validate_set_extensions (RISCVCPU *cpu,Error **errp) { +RISCVCPUClass *mcc =RISCV_CPU_GET_CLASS (cpu);CPURISCVState *env = &cpu->env;Error *local_err =NULL ;
@@ -605,7 +605,7 @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)cpu_cfg_ext_auto_update (cpu,CPU_CFG_OFFSET (ext_zcb), true);cpu_cfg_ext_auto_update (cpu,CPU_CFG_OFFSET (ext_zcmp), true);cpu_cfg_ext_auto_update (cpu,CPU_CFG_OFFSET (ext_zcmt), true); -if (riscv_has_ext (env,RVF ) && env->misa_mxl_max ==MXL_RV32 ) { +if (riscv_has_ext (env,RVF ) && mcc->misa_mxl_max ==MXL_RV32 ) {cpu_cfg_ext_auto_update (cpu,CPU_CFG_OFFSET (ext_zcf), true); } }
@@ -613,7 +613,7 @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)/* zca, zcd and zcf has a PRIV 1.12.0 restriction */ if (riscv_has_ext (env,RVC ) && env->priv_ver >=PRIV_VERSION_1_12_0 ) {cpu_cfg_ext_auto_update (cpu,CPU_CFG_OFFSET (ext_zca), true); -if (riscv_has_ext (env,RVF ) && env->misa_mxl_max ==MXL_RV32 ) { +if (riscv_has_ext (env,RVF ) && mcc->misa_mxl_max ==MXL_RV32 ) {cpu_cfg_ext_auto_update (cpu,CPU_CFG_OFFSET (ext_zcf), true); }if (riscv_has_ext (env,RVD )) {
@@ -621,7 +621,7 @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) } } -if (env->misa_mxl_max !=MXL_RV32 && cpu->cfg.ext_zcf) { +if (mcc->misa_mxl_max !=MXL_RV32 && cpu->cfg.ext_zcf) {error_setg (errp,"Zcf extension is only relevant to RV32" );return ; }
@@ -1334,7 +1334,7 @@ static void riscv_init_max_cpu_extensions(Object *obj)const RISCVCPUMultiExtConfig *prop;/* Enable RVG, RVJ and RVV that are disabled by default */ -riscv_cpu_set_misa (env, env->misa_mxl, env->misa_ext |RVG |RVJ |RVV ); +riscv_cpu_set_misa_ext (env, env->misa_ext |RVG |RVJ |RVV );for (prop = riscv_cpu_extensions; prop && prop->name; prop++) {isa_ext_update_enabled (cpu, prop->offset, true);
target/riscv/translate.c +2 -1
@@ -1168,6 +1168,7 @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) {DisasContext *ctx =container_of (dcbase, DisasContext, base);CPURISCVState *env =cpu_env (cs); +RISCVCPUClass *mcc =RISCV_CPU_GET_CLASS (cs);RISCVCPU *cpu =RISCV_CPU (cs);uint32_t tb_flags = ctx->base.tb->flags;
@@ -1189,7 +1190,7 @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) ctx->cfg_vta_all_1s = cpu->cfg.rvv_ta_all_1s; ctx->vstart_eq_zero =FIELD_EX32 (tb_flags,TB_FLAGS ,VSTART_EQ_ZERO ); ctx->vl_eq_vlmax =FIELD_EX32 (tb_flags,TB_FLAGS ,VL_EQ_VLMAX ); - ctx->misa_mxl_max = env->misa_mxl_max; + ctx->misa_mxl_max = mcc->misa_mxl_max; ctx->xl =FIELD_EX32 (tb_flags,TB_FLAGS ,XL ); ctx->address_xl =FIELD_EX32 (tb_flags,TB_FLAGS ,AXL ); ctx->cs = cs;
Signature · 1 line
2.39.2
[PULL 22/22] docs/devel: document some plugin assumptions
In reply to Alex BennéeWhile we attempt to hide implementation details from the plugin we shouldn't be totally obtuse. Let the user know what they can and can't expect with the various instrumentation options.
Message-Id: <[email protected]>
docs/devel/tcg-plugins.rst +49 -0
@@ -112,6 +112,55 @@ details are opaque to plugins. The plugin is able to query select details of instructions and system configuration only through the exported *qemu_plugin* functions. +However the following assumptions can be made: + +Translation Blocks +++++++++++++++++++ + +All code will go through a translation phase although not all +translations will be necessarily be executed. You need to instrument +actual executions to track what is happening. + +It is quite normal to see the same address translated multiple times. +If you want to track the code in system emulation you should examine +the underlying physical address (``qemu_plugin_insn_haddr``) to take +into account the effects of virtual memory although if the system does +paging this will change too. + +Not all instructions in a block will always execute so if its +important to track individual instruction execution you need to +instrument them directly. However asynchronous interrupts will not +change control flow mid-block. + +Instructions +++++++++++++ + +Instruction instrumentation runs before the instruction executes. You +can be can be sure the instruction will be dispatched, but you can't +be sure it will complete. Generally this will be because of a +synchronous exception (e.g. SIGILL) triggered by the instruction +attempting to execute. If you want to be sure you will need to +instrument the next instruction as well. See the ``execlog.c`` plugin +for examples of how to track this and finalise details after execution. + +Memory Accesses ++++++++++++++++ + +Memory callbacks are called after a successful load or store. +Unsuccessful operations (i.e. faults) will not be visible to memory +instrumentation although the execution side effects can be observed +(e.g. entering a exception handler). + +System Idle and Resume States ++++++++++++++++++++++++++++++ + +The ``qemu_plugin_register_vcpu_idle_cb`` and +``qemu_plugin_register_vcpu_resume_cb`` functions can be used to track +when CPUs go into and return from sleep states when waiting for +external I/O. Be aware though that these may occur less frequently +than in real HW due to the inefficiencies of emulation giving less +chance for the CPU to idle. + Internals ---------
Signature · 1 line
2.39.2
[PULL 20/22] contrib/plugins: optimise the register value tracking
In reply to Alex BennéeThis adds an additional flag which attempts to optimise the register tracking by only instrumenting instructions which are likely to change its value. This relies on the disassembler showing up the register names in disassembly so is only enabled when asked for.
Message-Id: <[email protected]>
docs/devel/tcg-plugins.rst +9 -1
@@ -503,7 +503,15 @@ registers with multiple ``reg`` options. You can also use glob style matching if $ qemu-system-arm $(QEMU_ARGS) \ -plugin ./contrib/plugins/libexeclog.so,reg=\*_el2,reg=sp -d plugin -Be aware that each additional register to check will slow down execution quite considerably. +Be aware that each additional register to check will slow down +execution quite considerably. You can optimise the number of register +checks done by using the rdisas option. This will only instrument +instructions that mention the registers in question in disassembly. +This is not foolproof as some instructions implicitly change +instructions. You can use the ifilter to catch these cases: + + $ qemu-system-arm $(QEMU_ARGS) \ + -plugin ./contrib/plugins/libexeclog.so,ifilter=msr,ifilter=blr,reg=x30,reg=\*_el1,rdisas=on - contrib/plugins/cache.c
contrib/plugins/execlog.c +158 -33
296 lines not on this page · raw message
Signature · 1 line
2.39.2
[PULL 14/22] gdbstub: Add members to identify registers to GDBFeature
In reply to Alex BennéeFrom: Akihiko Odaki <[email protected]>
These members will be used to help plugins to identify registers. The added members in instances of GDBFeature dynamically generated by CPUs will be filled in later changes.
Message-Id: <[email protected]>
Message-Id: <[email protected]>
include/exec/gdbstub.h +3 -0
@@ -13,12 +13,15 @@typedef struct GDBFeature {const char *xmlname;const char *xml; +const char *name; +const char *const *regs;int num_regs; }GDBFeature ;typedef struct GDBFeatureBuilder {GDBFeature *feature;GPtrArray *xml; +GPtrArray *regs;int base_reg; }GDBFeatureBuilder ;
gdbstub/gdbstub.c +9 -3
@@ -419,9 +419,10 @@ void gdb_feature_builder_init(GDBFeatureBuilder *builder, GDBFeature *feature, builder->feature = feature; builder->xml =g_ptr_array_new ();g_ptr_array_add (builder->xml, header); + builder->regs =g_ptr_array_new (); builder->base_reg = base_reg; feature->xmlname = xmlname; - feature->num_regs =0 ; + feature->name = name; } void gdb_feature_builder_append_tag(const GDBFeatureBuilder *builder,
@@ -440,10 +441,12 @@ void gdb_feature_builder_append_reg(const GDBFeatureBuilder *builder,const char *type, const char *group) { - if (builder->feature->num_regs < regnum) { - builder->feature->num_regs = regnum; + if (builder->regs->len <= regnum) { + g_ptr_array_set_size(builder->regs, regnum + 1); } + builder->regs->pdata[regnum] = (gpointer *)name; +if (group) { gdb_feature_builder_append_tag( builder,
@@ -469,6 +472,9 @@ void gdb_feature_builder_end(const GDBFeatureBuilder *builder) }g_ptr_array_free (builder->xml, TRUE); + + builder->feature->num_regs = builder->regs->len; + builder->feature->regs = (void *)g_ptr_array_free (builder->regs, FALSE); }const GDBFeature *gdb_find_static_feature (const char *xmlname)
target/riscv/gdbstub.c +1 -3
@@ -266,11 +266,9 @@ static GDBFeature *riscv_gen_dynamic_csr_feature(CPUState *cs, int base_reg) } predicate = csr_ops[i].predicate;if (predicate && (predicate (env, i) ==RISCV_EXCP_NONE )) { - g_autofree char *dynamic_name = NULL; name = csr_ops[i].name;if (!name) { - dynamic_name =g_strdup_printf ("csr%03x" , i); - name = dynamic_name; + name =g_strdup_printf ("csr%03x" , i); } gdb_feature_builder_append_reg(&builder, name, bitsize, i,
scripts/feature_to_c.py +13 -1
@@ -50,7 +50,9 @@ def writeliteral(indent, bytes): sys.stderr.write(f'unexpected start tag: {element.tag}\n') exit(1) + feature_name = element.attrib['name'] regnum = 0 + regnames = [] regnums = [] tags = ['feature'] for event, element in events:
@@ -67,6 +69,7 @@ def writeliteral(indent, bytes): if 'regnum' in element.attrib: regnum = int(element.attrib['regnum']) + regnames.append(element.attrib['name']) regnums.append(regnum) regnum += 1
@@ -85,6 +88,15 @@ def writeliteral(indent, bytes): writeliteral(8, bytes(os.path.basename(input), 'utf-8')) sys.stdout.write(',\n') writeliteral(8, read) - sys.stdout.write(f',\n {num_regs},\n }},\n') + sys.stdout.write(',\n') + writeliteral(8, bytes(feature_name, 'utf-8')) + sys.stdout.write(',\n (const char * const []) {\n') + + for index, regname in enumerate(regnames): + sys.stdout.write(f' [{regnums[index] - base_reg}] =\n') + writeliteral(16, bytes(regname, 'utf-8')) + sys.stdout.write(',\n') + + sys.stdout.write(f' }},\n {num_regs},\n }},\n') sys.stdout.write(' { NULL }\n};\n')
Signature · 1 line
2.39.2
[PULL 21/22] docs/devel: lift example and plugin API sections up
In reply to Alex BennéeThis makes them a bit more visible in the TCG emulation menu rather than hiding them away bellow the ToC limit.
Message-Id: <[email protected]>
docs/devel/tcg-plugins.rst +3 -3
@@ -143,7 +143,7 @@ requested. The plugin isn't completely uninstalled until the safe work has executed while all vCPUs are quiescent. Example Plugins ---------------- +=============== There are a number of plugins included with QEMU and you are encouraged to contribute your own plugins plugins upstream. There is a
@@ -591,8 +591,8 @@ The plugin has a number of arguments, all of them are optional: configuration arguments implies ``l2=on``. (default: N = 2097152 (2MB), B = 64, A = 16) -API ---- +Plugin API +========== The following API is generated from the inline documentation in ``include/qemu/qemu-plugin.h``. Please ensure any updates to the API
Signature · 1 line
2.39.2
[PULL 19/22] contrib/plugins: extend execlog to track register changes
In reply to Alex BennéeWith the new plugin register API we can now track changes to register values. Currently the implementation is fairly dumb which will slow down if a large number of register values are being tracked. This could be improved by only instrumenting instructions which mention registers we are interested in tracking.
Example usage:
./qemu-aarch64 -D plugin.log -d plugin \
-cpu max,sve256=on \
-plugin contrib/plugins/libexeclog.so,reg=sp,reg=z\* \
./tests/tcg/aarch64-linux-user/sha512-svewill display in the execlog any changes to the stack pointer (sp) and the SVE Z registers.
Message-Id: <[email protected]>
Based-On: <[email protected]>
docs/devel/tcg-plugins.rst +8 -1
@@ -497,6 +497,14 @@ arguments if required:: $ qemu-system-arm $(QEMU_ARGS) \ -plugin ./contrib/plugins/libexeclog.so,ifilter=st1w,afilter=0x40001808 -d plugin +This plugin can also dump registers when they change value. Specify the name of the +registers with multiple ``reg`` options. You can also use glob style matching if you wish:: + + $ qemu-system-arm $(QEMU_ARGS) \ + -plugin ./contrib/plugins/libexeclog.so,reg=\*_el2,reg=sp -d plugin + +Be aware that each additional register to check will slow down execution quite considerably. + - contrib/plugins/cache.c Cache modelling plugin that measures the performance of a given L1 cache
@@ -583,4 +591,3 @@ The following API is generated from the inline documentation in include the full kernel-doc annotations. .. kernel-doc:: include/qemu/qemu-plugin.h -
contrib/plugins/execlog.c +145 -44
271 lines not on this page · raw message
Signature · 1 line
2.39.2
[PULL 11/22] gdbstub: Simplify XML lookup
In reply to Alex BennéeFrom: Akihiko Odaki <[email protected]>
Now we know all instances of GDBFeature that is used in CPU so we can traverse them to find XML. This removes the need for a CPU-specific lookup function for dynamic XMLs.
Message-Id: <[email protected]>
Message-Id: <[email protected]>
include/exec/gdbstub.h +6 -0
@@ -27,6 +27,12 @@ typedef struct GDBFeatureBuilder {typedef int (*gdb_get_reg_cb )(CPUState *cpu,GByteArray *buf,int reg);typedef int (*gdb_set_reg_cb )(CPUState *cpu,uint8_t *buf,int reg); +/** +* gdb_init_cpu(): Initialize the CPU for gdbstub. +* @cpu: The CPU to be initialized. +*/ +void gdb_init_cpu (CPUState *cpu); +/** * gdb_register_coprocessor() - register a supplemental set of registers * @cpu - the CPU associated with registers
gdbstub/gdbstub.c +60 -58
174 lines not on this page · raw message
hw/core/cpu-common.c +3 -2
@@ -27,6 +27,7 @@#include "qemu/main-loop.h" #include "exec/log.h" #include "exec/cpu-common.h" +#include "exec/gdbstub.h" #include "qemu/error-report.h" #include "qemu/qemu-print.h" #include "sysemu/tcg.h"
@@ -240,11 +241,10 @@ static void cpu_common_unrealizefn(DeviceState *dev)static void cpu_common_initfn (Object *obj) {CPUState *cpu =CPU (obj); -CPUClass *cc =CPU_GET_CLASS (obj); +gdb_init_cpu (cpu); cpu->cpu_index =UNASSIGNED_CPU_INDEX ; cpu->cluster_index =UNASSIGNED_CLUSTER_INDEX ; - cpu->gdb_num_regs = cpu->gdb_num_g_regs = cc->gdb_num_core_regs;/* user-mode doesn't have configurable SMP topology */ /* the default value is changed by qemu_init_vcpu() for system-mode */ cpu->nr_cores =1 ;
@@ -264,6 +264,7 @@ static void cpu_common_finalize(Object *obj) {CPUState *cpu =CPU (obj); +g_array_free (cpu->gdb_regs, TRUE);qemu_lockcnt_destroy (&cpu->in_ioctl_lock);qemu_mutex_destroy (&cpu->work_mutex); }
Signature · 1 line
2.39.2
[PULL 17/22] plugins: add an API to read registers
In reply to Alex BennéeWe can only request a list of registers once the vCPU has been initialised so the user needs to use either call the get function on vCPU initialisation or during the translation phase.
We don't expose the reg number to the plugin instead hiding it behind an opaque handle. This allows for a bit of future proofing should the internals need to be changed while also being hashed against the CPUClass so we can handle different register sets per-vCPU in hetrogenous situations.
Having an internal state within the plugins also allows us to expand the interface in future (for example providing callbacks on register change if the translator can track changes).
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1706
Cc: Akihiko Odaki <[email protected]>
Message-Id: <[email protected]>
Based-on: <[email protected]>
include/qemu/qemu-plugin.h +49 -2
@@ -11,6 +11,7 @@#ifndef QEMU_QEMU_PLUGIN_H #define QEMU_QEMU_PLUGIN_H +#include <glib.h> #include <inttypes.h> #include <stdbool.h> #include <stddef.h>
@@ -227,8 +228,8 @@ struct qemu_plugin_insn;* @QEMU_PLUGIN_CB_R_REGS: callback reads the CPU's regs * @QEMU_PLUGIN_CB_RW_REGS: callback reads and writes the CPU's regs * -* Note: currently unused, plugins cannot read or change system -* register state. +* Note: currently QEMU_PLUGIN_CB_RW_REGS is unused, plugins cannot change +* system register state. */ enum qemu_plugin_cb_flags {QEMU_PLUGIN_CB_NO_REGS ,
@@ -708,4 +709,50 @@ uint64_t qemu_plugin_end_code(void);QEMU_PLUGIN_API uint64_t qemu_plugin_entry_code(void); +/** struct qemu_plugin_register - Opaque handle for register access */ +struct qemu_plugin_register ; + +/** +* typedef qemu_plugin_reg_descriptor - register descriptions +* +* @handle: opaque handle for retrieving value with qemu_plugin_read_register +* @name: register name +* @feature: optional feature descriptor, can be NULL +*/ +typedef struct { +struct qemu_plugin_register *handle; +const char *name; +const char *feature; +}qemu_plugin_reg_descriptor ; + +/** +* qemu_plugin_get_registers() - return register list for vCPU +* @vcpu_index: vcpu to query +* +* Returns a GArray of qemu_plugin_reg_descriptor or NULL. Caller +* frees the array (but not the const strings). +* +* Should be used from a qemu_plugin_register_vcpu_init_cb() callback +* after the vCPU is initialised. +*/ +GArray *qemu_plugin_get_registers (unsigned int vcpu_index); + +/** +* qemu_plugin_read_register() - read register +* +* @vcpu: vcpu index +* @handle: a @qemu_plugin_reg_handle handle +* @buf: A GByteArray for the data owned by the plugin +* +* This function is only available in a context that register read access is +* explicitly requested. +* +* Returns the size of the read register. The content of @buf is in target byte +* order. On failure returns -1 +*/ +int qemu_plugin_read_register (unsigned int vcpu, +struct qemu_plugin_register *handle, +GByteArray *buf); + +#endif /* QEMU_QEMU_PLUGIN_H */
plugins/api.c +111 -0
130 lines not on this page · raw message
plugins/qemu-plugins.symbols +2 -0
@@ -3,6 +3,7 @@ qemu_plugin_end_code; qemu_plugin_entry_code; qemu_plugin_get_hwaddr; + qemu_plugin_get_registers; qemu_plugin_hwaddr_device_name; qemu_plugin_hwaddr_is_io; qemu_plugin_hwaddr_phys_addr;
@@ -20,6 +21,7 @@ qemu_plugin_n_vcpus; qemu_plugin_outs; qemu_plugin_path_to_binary; + qemu_plugin_read_register; qemu_plugin_register_atexit_cb; qemu_plugin_register_flush_cb; qemu_plugin_register_vcpu_exit_cb;
Signature · 1 line
2.39.2
Re: [PULL 17/22] plugins: add an API to read registers
Quoted 122 lines · Alex Bennée
We can only request a list of registers once the vCPU has been initialised so the user needs to use either call the get function on vCPU initialisation or during the translation phase.
We don't expose the reg number to the plugin instead hiding it behind an opaque handle. This allows for a bit of future proofing should the internals need to be changed while also being hashed against the CPUClass so we can handle different register sets per-vCPU in hetrogenous situations.
Having an internal state within the plugins also allows us to expand the interface in future (for example providing callbacks on register change if the translator can track changes).
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1706
Cc: Akihiko Odaki <[email protected]>
Message-Id: <[email protected]>
Based-on: <[email protected]>Signed-off-by Alex Bennée <[email protected]>Reviewed-by Pierrick Bouvier <[email protected]>include/qemu/qemu-plugin.h +49
-2@@ -11,6 +11,7 @@#ifndef QEMU_QEMU_PLUGIN_H #define QEMU_QEMU_PLUGIN_H +#include <glib.h> #include <inttypes.h> #include <stdbool.h> #include <stddef.h> @@ -227,8 +228,8 @@ struct qemu_plugin_insn;* @QEMU_PLUGIN_CB_R_REGS: callback reads the CPU's regs * @QEMU_PLUGIN_CB_RW_REGS: callback reads and writes the CPU's regs * -* Note: currently unused, plugins cannot read or change system -* register state. +* Note: currently QEMU_PLUGIN_CB_RW_REGS is unused, plugins cannot change +* system register state. */ enum qemu_plugin_cb_flags {QEMU_PLUGIN_CB_NO_REGS ,@@ -708,4 +709,50 @@ uint64_t qemu_plugin_end_code(void);QEMU_PLUGIN_API uint64_t qemu_plugin_entry_code(void); +/** struct qemu_plugin_register - Opaque handle for register access */ +struct qemu_plugin_register ; + +/** +* typedef qemu_plugin_reg_descriptor - register descriptions +* +* @handle: opaque handle for retrieving value with qemu_plugin_read_register +* @name: register name +* @feature: optional feature descriptor, can be NULL +*/ +typedef struct { +struct qemu_plugin_register *handle; +const char *name; +const char *feature; +}qemu_plugin_reg_descriptor ; + +/** +* qemu_plugin_get_registers() - return register list for vCPU +* @vcpu_index: vcpu to query +* +* Returns a GArray of qemu_plugin_reg_descriptor or NULL. Caller +* frees the array (but not the const strings). +* +* Should be used from a qemu_plugin_register_vcpu_init_cb() callback +* after the vCPU is initialised. +*/ +GArray *qemu_plugin_get_registers (unsigned int vcpu_index); + +/** +* qemu_plugin_read_register() - read register +* +* @vcpu: vcpu index +* @handle: a @qemu_plugin_reg_handle handle +* @buf: A GByteArray for the data owned by the plugin +* +* This function is only available in a context that register read access is +* explicitly requested. +* +* Returns the size of the read register. The content of @buf is in target byte +* order. On failure returns -1 +*/ +int qemu_plugin_read_register (unsigned int vcpu, +struct qemu_plugin_register *handle, +GByteArray *buf); + +#endif /* QEMU_QEMU_PLUGIN_H */ plugins/api.c +3
-0@@ -8,6 +8,7 @@* * qemu_plugin_tb * qemu_plugin_insn +* qemu_plugin_register * * Which can then be passed back into the API to do additional things. * As such all the public functions in here are exported in @@ -35,10 +36,12 @@*/ #include "qemu/osdep.h" +#include "qemu/main-loop.h" #include "qemu/plugin.h" #include "qemu/log.h" #include "tcg/tcg.h" #include "exec/exec-all.h" +#include "exec/gdbstub.h" #include "exec/ram_addr.h" #include "disas/disas.h" #include "plugin.h" @@ -435,3 +438,111 @@ uint64_t qemu_plugin_entry_code(void)#endif
plugins/api.c uint64_t qemu_plugin_entry_code(void) · line 448
Quoted 10 lines
plugins/api.c +8
-0return entry; } + +/* +* Register handles +* +* The plugin infrastructure keeps hold of these internal data +* structures which are presented to plugins as opaque handles. They +* are global to the system and therefor additions to the hash table +* must be protected by the @reg_handle_lock.
The BQL should be used instead. This lock only serializes the plugin access, but the whole gdbstub code needs to be serialized to ensure the correct behaving of e.g., gdb_get_register_list().
plugins/api.c uint64_t qemu_plugin_entry_code(void) · line 452
Quoted 4 lines
plugins/api.c +4
-0+* +* In order to future proof for up-coming heterogeneous work we want +* different entries for each CPU type while sharing them in the +* common case of multiple cores of the same type.
I don't think such an effort should be done in the plugin code, but it should be done in the common gdbstub code.
GDB assumes all threads have the same set of registers, so gdbstub will need to take care of them by running distinct GDB servers for each processor type, for example. There is a good chance that gdbstub will duplicate similar logic.
Quoted 8 lines
plugins/api.c +8
-0+*/ + +static QemuMutex reg_handle_lock; + +struct qemu_plugin_register { +const char *name; +int gdb_reg_num; +};
plugins/api.c uint64_t qemu_plugin_entry_code(void) · line 470
Quoted 10 lines
plugins/api.c +10
-0+ +static GHashTable *reg_handles;/* hash table of PluginReg */ + +/* Generate a stable key - would xxhash be overkill? */ +static gpointer cpu_plus_reg_to_key (CPUState *cs,int gdb_regnum) +{ +uintptr_t key = (uintptr_t ) cs->cc; + key ^= gdb_regnum; +return GUINT_TO_POINTER (key); +}
This is, theoretically, prone to collisions and unsafe.
Re: [PULL 17/22] plugins: add an API to read registers
Quoted 124 lines · Akihiko Odaki
Quoted 123 lines · Alex Bennée
We can only request a list of registers once the vCPU has been initialised so the user needs to use either call the get function on vCPU initialisation or during the translation phase.
We don't expose the reg number to the plugin instead hiding it behind
an opaque handle. This allows for a bit of future proofing should the internals need to be changed while also being hashed against the CPUClass so we can handle different register sets per-vCPU in hetrogenous situations.
Having an internal state within the plugins also allows us to expand the interface in future (for example providing callbacks on register change if the translator can track changes).
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1706
Cc: Akihiko Odaki <[email protected]>
Message-Id: <[email protected]>
Based-on: <[email protected]>Signed-off-by Alex Bennée <[email protected]>Reviewed-by Pierrick Bouvier <[email protected]>include/qemu/qemu-plugin.h +2
-2@@ -11,6 +11,7 @@#ifndef QEMU_QEMU_PLUGIN_H #define QEMU_QEMU_PLUGIN_H +#include <glib.h>#include <inttypes.h> #include <stdbool.h> #include <stddef.h> @@ -227,8 +228,8 @@ struct qemu_plugin_insn;* @QEMU_PLUGIN_CB_R_REGS: callback reads the CPU's regs * @QEMU_PLUGIN_CB_RW_REGS: callback reads and writes the CPU's regs * -* Note: currently unused, plugins cannot read or change system -* register state. +* Note: currently QEMU_PLUGIN_CB_RW_REGS is unused, plugins cannot change +* system register state. */ enum qemu_plugin_cb_flags {QEMU_PLUGIN_CB_NO_REGS ,@@ -708,4 +709,50 @@ uint64_t qemu_plugin_end_code(void);QEMU_PLUGIN_API uint64_t qemu_plugin_entry_code(void); +/** struct qemu_plugin_register - Opaque handle for registeraccess */
include/qemu/qemu-plugin.h +45
-0+struct qemu_plugin_register ; + +/** +* typedef qemu_plugin_reg_descriptor - register descriptions +* +* @handle: opaque handle for retrieving value with qemu_plugin_read_register +* @name: register name +* @feature: optional feature descriptor, can be NULL +*/ +typedef struct { +struct qemu_plugin_register *handle; +const char *name; +const char *feature; +}qemu_plugin_reg_descriptor ; + +/** +* qemu_plugin_get_registers() - return register list for vCPU +* @vcpu_index: vcpu to query +* +* Returns a GArray of qemu_plugin_reg_descriptor or NULL. Caller +* frees the array (but not the const strings). +* +* Should be used from a qemu_plugin_register_vcpu_init_cb() callback +* after the vCPU is initialised. +*/ +GArray *qemu_plugin_get_registers (unsigned int vcpu_index); + +/** +* qemu_plugin_read_register() - read register +* +* @vcpu: vcpu index +* @handle: a @qemu_plugin_reg_handle handle +* @buf: A GByteArray for the data owned by the plugin +* +* This function is only available in a context that register read access is +* explicitly requested. +* +* Returns the size of the read register. The content of @buf is in target byte +* order. On failure returns -1 +*/ +int qemu_plugin_read_register (unsigned int vcpu, +struct qemu_plugin_register *handle, +GByteArray *buf); + +#endif /* QEMU_QEMU_PLUGIN_H */ plugins/api.c +7
-0@@ -8,6 +8,7 @@* * qemu_plugin_tb * qemu_plugin_insn +* qemu_plugin_register * * Which can then be passed back into the API to do additional things. * As such all the public functions in here are exported in @@ -35,10 +36,12 @@*/ #include "qemu/osdep.h" +#include "qemu/main-loop.h" #include "qemu/plugin.h" #include "qemu/log.h" #include "tcg/tcg.h" #include "exec/exec-all.h" +#include "exec/gdbstub.h" #include "exec/ram_addr.h" #include "disas/disas.h" #include "plugin.h" @@ -435,3 +438,111 @@ uint64_t qemu_plugin_entry_code(void)#endif return entry; } + +/* +* Register handles +*
Quoted 8 lines
plugins/api.c uint64_t qemu_plugin_entry_code(void) · line 448
Quoted 4 lines
plugins/api.c +4
-0+* The plugin infrastructure keeps hold of these internal data +* structures which are presented to plugins as opaque handles. They +* are global to the system and therefor additions to the hash table +* must be protected by the @reg_handle_lock. The BQL should be used instead. This lock only serializes the plugin access, but the whole gdbstub code needs to be serialized to ensure the correct behaving of e.g.,
gdb_get_register_list().
Why does gdb_get_register_list need to take the BQL? It only works through per-cpu structures. The reg_handle_lock only protects the hash table itself.
Quoted 8 lines
plugins/api.c uint64_t qemu_plugin_entry_code(void) · line 452
Quoted 5 lines
plugins/api.c +4
-0+* +* In order to future proof for up-coming heterogeneous work we want +* different entries for each CPU type while sharing them in the +* common case of multiple cores of the same type. I don't think such an effort should be done in the plugin code, but it should be done in the common gdbstub code.
Sure - we can always move it later.
Quoted 4 lines
GDB assumes all threads have the same set of registers, so gdbstub will need to take care of them by running distinct GDB servers for each processor type, for example. There is a good chance that gdbstub will duplicate similar logic.
Which logic?
Quoted 21 lines
Quoted 9 lines
plugins/api.c +8
-0+*/ + +static QemuMutex reg_handle_lock; + +struct qemu_plugin_register { +const char *name; +int gdb_reg_num; +};plugins/api.c uint64_t qemu_plugin_entry_code(void) · line 470
Quoted 10 lines
plugins/api.c +10
-0+ +static GHashTable *reg_handles;/* hash table of PluginReg */ + +/* Generate a stable key - would xxhash be overkill? */ +static gpointer cpu_plus_reg_to_key (CPUState *cs,int gdb_regnum) +{ +uintptr_t key = (uintptr_t ) cs->cc; + key ^= gdb_regnum; +return GUINT_TO_POINTER (key); +}This is, theoretically, prone to collisions and unsafe.
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
Re: [PULL 17/22] plugins: add an API to read registers
Quoted 148 lines · Alex Bennée
Quoted 124 lines · Akihiko Odaki
Quoted 123 lines · Alex Bennée
We can only request a list of registers once the vCPU has been initialised so the user needs to use either call the get function on vCPU initialisation or during the translation phase.
We don't expose the reg number to the plugin instead hiding it behind
an opaque handle. This allows for a bit of future proofing should the internals need to be changed while also being hashed against the CPUClass so we can handle different register sets per-vCPU in hetrogenous situations.
Having an internal state within the plugins also allows us to expand the interface in future (for example providing callbacks on register change if the translator can track changes).
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1706
Cc: Akihiko Odaki <[email protected]>
Message-Id: <[email protected]>
Based-on: <[email protected]>Signed-off-by Alex Bennée <[email protected]>Reviewed-by Pierrick Bouvier <[email protected]>include/qemu/qemu-plugin.h +2
-2@@ -11,6 +11,7 @@#ifndef QEMU_QEMU_PLUGIN_H #define QEMU_QEMU_PLUGIN_H +#include <glib.h>#include <inttypes.h> #include <stdbool.h> #include <stddef.h> @@ -227,8 +228,8 @@ struct qemu_plugin_insn;* @QEMU_PLUGIN_CB_R_REGS: callback reads the CPU's regs * @QEMU_PLUGIN_CB_RW_REGS: callback reads and writes the CPU's regs * -* Note: currently unused, plugins cannot read or change system -* register state. +* Note: currently QEMU_PLUGIN_CB_RW_REGS is unused, plugins cannot change +* system register state. */ enum qemu_plugin_cb_flags {QEMU_PLUGIN_CB_NO_REGS ,@@ -708,4 +709,50 @@ uint64_t qemu_plugin_end_code(void);QEMU_PLUGIN_API uint64_t qemu_plugin_entry_code(void); +/** struct qemu_plugin_register - Opaque handle for registeraccess */
include/qemu/qemu-plugin.h +45
-0+struct qemu_plugin_register ; + +/** +* typedef qemu_plugin_reg_descriptor - register descriptions +* +* @handle: opaque handle for retrieving value with qemu_plugin_read_register +* @name: register name +* @feature: optional feature descriptor, can be NULL +*/ +typedef struct { +struct qemu_plugin_register *handle; +const char *name; +const char *feature; +}qemu_plugin_reg_descriptor ; + +/** +* qemu_plugin_get_registers() - return register list for vCPU +* @vcpu_index: vcpu to query +* +* Returns a GArray of qemu_plugin_reg_descriptor or NULL. Caller +* frees the array (but not the const strings). +* +* Should be used from a qemu_plugin_register_vcpu_init_cb() callback +* after the vCPU is initialised. +*/ +GArray *qemu_plugin_get_registers (unsigned int vcpu_index); + +/** +* qemu_plugin_read_register() - read register +* +* @vcpu: vcpu index +* @handle: a @qemu_plugin_reg_handle handle +* @buf: A GByteArray for the data owned by the plugin +* +* This function is only available in a context that register read access is +* explicitly requested. +* +* Returns the size of the read register. The content of @buf is in target byte +* order. On failure returns -1 +*/ +int qemu_plugin_read_register (unsigned int vcpu, +struct qemu_plugin_register *handle, +GByteArray *buf); + +#endif /* QEMU_QEMU_PLUGIN_H */ plugins/api.c +7
-0@@ -8,6 +8,7 @@* * qemu_plugin_tb * qemu_plugin_insn +* qemu_plugin_register * * Which can then be passed back into the API to do additional things. * As such all the public functions in here are exported in @@ -35,10 +36,12 @@*/ #include "qemu/osdep.h" +#include "qemu/main-loop.h" #include "qemu/plugin.h" #include "qemu/log.h" #include "tcg/tcg.h" #include "exec/exec-all.h" +#include "exec/gdbstub.h" #include "exec/ram_addr.h" #include "disas/disas.h" #include "plugin.h" @@ -435,3 +438,111 @@ uint64_t qemu_plugin_entry_code(void)#endif return entry; } + +/* +* Register handles +* Quoted 8 lines
plugins/api.c uint64_t qemu_plugin_entry_code(void) · line 448
Quoted 4 lines
plugins/api.c +4
-0+* The plugin infrastructure keeps hold of these internal data +* structures which are presented to plugins as opaque handles. They +* are global to the system and therefor additions to the hash table +* must be protected by the @reg_handle_lock. The BQL should be used instead. This lock only serializes the plugin access, but the whole gdbstub code needs to be serialized to ensure the correct behaving of e.g.,
gdb_get_register_list().Why does
gdb_get_register_listneed to take the BQL? It only works through per-cpu structures. Thereg_handle_lockonly protects the hash table itself.Quoted 8 lines
plugins/api.c uint64_t qemu_plugin_entry_code(void) · line 452
Quoted 5 lines
plugins/api.c +4
-0+* +* In order to future proof for up-coming heterogeneous work we want +* different entries for each CPU type while sharing them in the +* common case of multiple cores of the same type. I don't think such an effort should be done in the plugin code, but it should be done in the common gdbstub code.
Quoted 8 lines
Sure - we can always move it later.
Quoted 4 lines
GDB assumes all threads have the same set of registers, so gdbstub will need to take care of them by running distinct GDB servers for each processor type, for example. There is a good chance that gdbstub will duplicate similar logic.
Which logic?
reg_handles, a GHashTable, is used to detect the duplicate definitions of a register in processors with same type, but such a logic is probably better off to be implemented in gdbstub; gdbstub should have one definition of register set for each type of processors in a system, and gdbstub can use it to start a distinct GDB server for the type. This way, gdbstub can ensure it exposes a homogeneous view for each GDB server as GDB requires.
If gdbstub already has such a logic, the plugin infrastructure can just query gdbstub for a common, shared register set used for a processor type; it will no longer have to check for duplicate definitions with a hash table.
Re: [PULL 17/22] plugins: add an API to read registers
Quoted 162 lines · Akihiko Odaki
Quoted 146 lines · Alex Bennée
Quoted 124 lines · Akihiko Odaki
Quoted 123 lines · Alex Bennée
We can only request a list of registers once the vCPU has been initialised so the user needs to use either call the get function on vCPU initialisation or during the translation phase.
We don't expose the reg number to the plugin instead hiding it behind
an opaque handle. This allows for a bit of future proofing should the internals need to be changed while also being hashed against the CPUClass so we can handle different register sets per-vCPU in hetrogenous situations.
Having an internal state within the plugins also allows us to expand the interface in future (for example providing callbacks on register change if the translator can track changes).
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1706
Cc: Akihiko Odaki <[email protected]>
Message-Id: <[email protected]>
Based-on: <[email protected]>Signed-off-by Alex Bennée <[email protected]>Reviewed-by Pierrick Bouvier <[email protected]>include/qemu/qemu-plugin.h +2
-2@@ -11,6 +11,7 @@#ifndef QEMU_QEMU_PLUGIN_H #define QEMU_QEMU_PLUGIN_H +#include <glib.h>#include <inttypes.h> #include <stdbool.h> #include <stddef.h> @@ -227,8 +228,8 @@ struct qemu_plugin_insn;* @QEMU_PLUGIN_CB_R_REGS: callback reads the CPU's regs * @QEMU_PLUGIN_CB_RW_REGS: callback reads and writes the CPU's regs * -* Note: currently unused, plugins cannot read or change system -* register state. +* Note: currently QEMU_PLUGIN_CB_RW_REGS is unused, plugins cannot change +* system register state. */ enum qemu_plugin_cb_flags {QEMU_PLUGIN_CB_NO_REGS ,@@ -708,4 +709,50 @@ uint64_t qemu_plugin_end_code(void);QEMU_PLUGIN_API uint64_t qemu_plugin_entry_code(void); +/** struct qemu_plugin_register - Opaque handle for registeraccess */
include/qemu/qemu-plugin.h +45
-0+struct qemu_plugin_register ; + +/** +* typedef qemu_plugin_reg_descriptor - register descriptions +* +* @handle: opaque handle for retrieving value with qemu_plugin_read_register +* @name: register name +* @feature: optional feature descriptor, can be NULL +*/ +typedef struct { +struct qemu_plugin_register *handle; +const char *name; +const char *feature; +}qemu_plugin_reg_descriptor ; + +/** +* qemu_plugin_get_registers() - return register list for vCPU +* @vcpu_index: vcpu to query +* +* Returns a GArray of qemu_plugin_reg_descriptor or NULL. Caller +* frees the array (but not the const strings). +* +* Should be used from a qemu_plugin_register_vcpu_init_cb() callback +* after the vCPU is initialised. +*/ +GArray *qemu_plugin_get_registers (unsigned int vcpu_index); + +/** +* qemu_plugin_read_register() - read register +* +* @vcpu: vcpu index +* @handle: a @qemu_plugin_reg_handle handle +* @buf: A GByteArray for the data owned by the plugin +* +* This function is only available in a context that register read access is +* explicitly requested. +* +* Returns the size of the read register. The content of @buf is in target byte +* order. On failure returns -1 +*/ +int qemu_plugin_read_register (unsigned int vcpu, +struct qemu_plugin_register *handle, +GByteArray *buf); + +#endif /* QEMU_QEMU_PLUGIN_H */ plugins/api.c +7
-0@@ -8,6 +8,7 @@* * qemu_plugin_tb * qemu_plugin_insn +* qemu_plugin_register * * Which can then be passed back into the API to do additional things. * As such all the public functions in here are exported in @@ -35,10 +36,12 @@*/ #include "qemu/osdep.h" +#include "qemu/main-loop.h" #include "qemu/plugin.h" #include "qemu/log.h" #include "tcg/tcg.h" #include "exec/exec-all.h" +#include "exec/gdbstub.h" #include "exec/ram_addr.h" #include "disas/disas.h" #include "plugin.h" @@ -435,3 +438,111 @@ uint64_t qemu_plugin_entry_code(void)#endif return entry; } + +/* +* Register handles +* Quoted 8 lines
plugins/api.c uint64_t qemu_plugin_entry_code(void) · line 448
Quoted 4 lines
plugins/api.c +4
-0+* The plugin infrastructure keeps hold of these internal data +* structures which are presented to plugins as opaque handles. They +* are global to the system and therefor additions to the hash table +* must be protected by the @reg_handle_lock. The BQL should be used instead. This lock only serializes the plugin access, but the whole gdbstub code needs to be serialized to ensure the correct behaving of e.g.,
gdb_get_register_list().Why does
gdb_get_register_listneed to take the BQL? It only works through per-cpu structures. Thereg_handle_lockonly protects the hash table itself.Quoted 8 lines
plugins/api.c uint64_t qemu_plugin_entry_code(void) · line 452
Quoted 5 lines
plugins/api.c +4
-0+* +* In order to future proof for up-coming heterogeneous work we want +* different entries for each CPU type while sharing them in the +* common case of multiple cores of the same type. I don't think such an effort should be done in the plugin code, but it should be done in the common gdbstub code.
Quoted 7 lines
Sure - we can always move it later.
Quoted 4 lines
GDB assumes all threads have the same set of registers, so gdbstub will need to take care of them by running distinct GDB servers for each processor type, for example. There is a good chance that gdbstub will duplicate similar logic.
Which logic?
reg_handles, a GHashTable, is used to detect the duplicate definitions of a register in processors with same type, but such a logic is probably better off to be implemented in gdbstub; gdbstub should have one definition of register set for each type of processors in a system, and gdbstub can use it to start a distinct GDB server for the type. This way, gdbstub can ensure it exposes a homogeneous view for each GDB server as GDB requires.
Quoted 4 lines
If gdbstub already has such a logic, the plugin infrastructure can just query gdbstub for a common, shared register set used for a processor type; it will no longer have to check for duplicate definitions with a hash table.
I think we can move this after the merge to do further clean-up. There are other register details plugins might want to track itself. For example the translator has knowledge of some registers that it knows when they are updated (due to using translator static TCGv defs). We wouldn't want to expose that via gdbstub.
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
[PULL 18/22] contrib/plugins: fix imatch
In reply to Alex BennéeWe can't directly save the ephemeral imatch from argv as that memory will get recycled.
Message-Id: <[email protected]>
contrib/plugins/execlog.c +1 -1
@@ -199,7 +199,7 @@ static void parse_insn_match(char *match)if (!imatches) { imatches =g_ptr_array_new (); } -g_ptr_array_add (imatches, match); +g_ptr_array_add (imatches,g_strdup (match)); }static void parse_vaddr_match (char *match)
Signature · 1 line
2.39.2
[PULL 15/22] plugins: Use different helpers when reading registers
In reply to Alex BennéeFrom: Akihiko Odaki <[email protected]>
This avoids optimizations incompatible when reading registers.
Message-Id: <[email protected]>
Message-Id: <[email protected]>
accel/tcg/plugin-helpers.h +2 -1
@@ -1,4 +1,5 @@#ifdef CONFIG_PLUGIN -DEF_HELPER_FLAGS_2(plugin_vcpu_udata_cb, TCG_CALL_NO_RWG | TCG_CALL_PLUGIN, void, i32, ptr) +DEF_HELPER_FLAGS_2(plugin_vcpu_udata_cb_no_wg, TCG_CALL_NO_WG | TCG_CALL_PLUGIN, void, i32, ptr) +DEF_HELPER_FLAGS_2(plugin_vcpu_udata_cb_no_rwg, TCG_CALL_NO_RWG | TCG_CALL_PLUGIN, void, i32, ptr) DEF_HELPER_FLAGS_4(plugin_vcpu_mem_cb, TCG_CALL_NO_RWG | TCG_CALL_PLUGIN, void, i32, i32, i64, ptr)#endif
include/qemu/plugin.h +1 -0
@@ -73,6 +73,7 @@ enum plugin_dyn_cb_type {enum plugin_dyn_cb_subtype {PLUGIN_CB_REGULAR , +PLUGIN_CB_REGULAR_R ,PLUGIN_CB_INLINE ,PLUGIN_N_CB_SUBTYPES , };
accel/tcg/plugin-gen.c +39 -4
102 lines not on this page · raw message
plugins/api.c +10 -2
@@ -89,7 +89,11 @@ void qemu_plugin_register_vcpu_tb_exec_cb(struct qemu_plugin_tb *tb, void *udata) {if (!tb->mem_only) { -plugin_register_dyn_cb__udata (&tb->cbs[PLUGIN_CB_REGULAR ], +int index = flags ==QEMU_PLUGIN_CB_R_REGS || + flags ==QEMU_PLUGIN_CB_RW_REGS ? +PLUGIN_CB_REGULAR_R :PLUGIN_CB_REGULAR ; + +plugin_register_dyn_cb__udata (&tb->cbs[index], cb, flags, udata); } }
@@ -109,7 +113,11 @@ void qemu_plugin_register_vcpu_insn_exec_cb(struct qemu_plugin_insn *insn, void *udata) {if (!insn->mem_only) { -plugin_register_dyn_cb__udata (&insn->cbs[PLUGIN_CB_INSN ][PLUGIN_CB_REGULAR ], +int index = flags ==QEMU_PLUGIN_CB_R_REGS || + flags ==QEMU_PLUGIN_CB_RW_REGS ? +PLUGIN_CB_REGULAR_R :PLUGIN_CB_REGULAR ; + +plugin_register_dyn_cb__udata (&insn->cbs[PLUGIN_CB_INSN ][index], cb, flags, udata); } }
Signature · 1 line
2.39.2
Quoted 16 lines · Alex Bennée
The following changes since commit
977542ded7e6b28d2bc077bcda24568c716e393c:Merge tag 'pull-testing-updates-120124-2' of https://gitlab.com/stsquad/qemu into staging (2024-01-12 14:02:53 +0000)
are available in the Git repository at:
https://gitlab.com/stsquad/qemu.git tags/pull-registers-for-plugins-160124-2
for you to fetch changes up to
87bed6910aa0d0942244b5eedee60b4f8b162c05:docs/devel: document some plugin assumptions (2024-01-16 10:34:20 +0000)
----------------------------------------------------------------
read-only register access for plugins:
Quoted 12 lines
- move
misa_mxlto CPU class for riscv
- use GDBFeature for arm XML
- use GDBFeature for ppc XML
- use GDBFeature for riscv XML
- unify gdb code to use GDBFeature
- move dynamic XML generation to core GDB code
- provide introspection APIs for rest of QEMU
- expose a plugin API to access registers
- fix memory re-use in execlog
- extend execlog to track registers
- optimise instrumentation based on disassembly
- tweak API docs and expand on assumptions
I see that Akihiko has asked for this not to be merged, so I'll drop this pull req.
Akihiko: for the future, if you want an on-list pullreq to not be merged, please reply to the cover letter, not to an individual patch. I am very unlikely to notice replies to individual patches before I do a merge. (I only noticed in this case because somebody happened to point it out to me on IRC.)
thanks
-- PMM