qemu/hw/core
Peter Maydell b4ae54989b hw/core/cpu-common: Don't init gdbstub until cpu_exec_realizefn()
Currently we call gdb_init_cpu() in cpu_common_initfn(), which is
very early in the CPU object's init->realize creation sequence.  In
particular this happens before the architecture-specific subclass's
init fn has even run.  This means that gdb_init_cpu() can only do
things that depend strictly on the class, not on the object, because
the CPUState* that it is passed is currently half-initialized.

In commit a1f728ecc9 we accidentally broke this rule, by adding
a call to the gdb_get_core_xml_file method which takes the CPUState.
At the moment we get away with this because the only implementation
doesn't actually look at the pointer it is passed.  However the whole
reason we created that method was so that we could make the "which
XML file?" decision based on a property of the CPU object, and we
currently can't change the Arm implementation of the method to do
what we want without causing wrong behaviour or a crash.

The ordering restrictions here are:
 * we must call gdb_init_cpu before:
   - any call to gdb_register_coprocessor()
   - any use of the gdb_num_regs field (this is only used
     in code that's about to call gdb_register_coprocessor()
     and wants to know the first register number of the
     set of registers it's about to add)
 * we must call gdb_init_cpu after CPU properties have been
   set, which is to say somewhere in realize

The function cpu_exec_realizefn() meets both of these requirements,
as it is called by the architecture-specific CPU realize function
early in realize, before any calls ot gdb_register_coprocessor().
Move the gdb_init_cpu() call to there.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@amd.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-id: 20250429132200.605611-4-peter.maydell@linaro.org
2025-05-14 14:29:45 +01:00
..
bus.c qom: Make InterfaceInfo[] uses const 2025-04-25 17:00:41 +02:00
clock-vmstate.c hw/core: Constify VMState 2023-12-29 11:17:30 +11:00
clock.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
cpu-common.c hw/core/cpu-common: Don't init gdbstub until cpu_exec_realizefn() 2025-05-14 14:29:45 +01:00
cpu-system.c exec: Rename target_words_bigendian() -> target_big_endian() 2025-04-25 17:00:42 +02:00
cpu-user.c cpus: Remove CPUClass::has_work() handler 2025-03-09 17:00:47 +01:00
eif.c hw/core/eif: Use stateful qcrypto apis 2024-12-13 15:26:58 +01:00
eif.h hw/core: Add Enclave Image Format (EIF) related helpers 2024-10-31 18:28:32 +01:00
fw-path-provider.c Include qemu/module.h where needed, drop it from qemu-common.h 2019-06-12 13:18:33 +02:00
generic-loader.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
gpio.c qdev: Use machine_get_container() 2025-01-09 18:16:24 +01:00
guest-loader.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
guest-loader.h hw/core: implement a guest-loader to support static hypervisor guests 2021-03-10 15:34:11 +00:00
hotplug.c call HotplugHandler->plug() as the last step in device realization 2018-10-19 13:44:12 +02:00
irq.c hw/irq: Introduce qemu_init_irqs() helper 2025-01-31 19:36:44 +01:00
Kconfig hw/core: Add Enclave Image Format (EIF) related helpers 2024-10-31 18:28:32 +01:00
loader-fit.c include/system: Move exec/memory.h to system/memory.h 2025-04-23 14:08:21 -07:00
loader.c hw/core/loader: Fix type conflict of GLib function pointers 2025-04-25 17:00:42 +02:00
machine-hmp-cmds.c qapi: Move include/qapi/qmp/ to include/qobject/ 2025-02-10 15:33:16 +01:00
machine-qmp-cmds.c qemu: Convert target_name() to TargetInfo API 2025-04-25 17:09:58 +02:00
machine-smp.c i386/cpu: add has_caches flag to check smp_cache configuration 2025-02-25 16:18:12 +01:00
machine.c hw/core/machine: Fix indentation 2025-05-09 23:49:26 +03:00
meson.build hw/core: Move unconditional files to libsystem_ss, libuser_ss 2025-04-23 14:08:39 -07:00
nmi.c hw/core: Improve error message when machine doesn't provide NMIs 2023-02-23 14:10:17 +01:00
null-machine.c include/system: Move exec/address-spaces.h to system/address-spaces.h 2025-04-23 14:08:21 -07:00
numa.c include: Rename sysemu/ -> system/ 2024-12-20 17:44:56 +01:00
or-irq.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
platform-bus.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
ptimer.c include/exec: Split out icount.h 2025-04-23 14:08:44 -07:00
qdev-clock.c clock: inline most of qdev_init_clocklist 2024-12-10 18:49:24 +01:00
qdev-fw.c Include hw/qdev-properties.h less 2019-08-16 13:31:53 +02:00
qdev-hotplug.c hw/qdev: Check machine_hotplug_handler in hotplug_unplug_allowed_common 2025-01-13 17:16:03 +01:00
qdev-prop-internal.h qdev: Make qdev_propinfo_get_uint16() static 2020-12-15 10:02:07 -05:00
qdev-properties-system.c cleanup: Drop pointless return at end of function 2025-04-24 09:33:42 +02:00
qdev-properties.c qdev, rust/hpet: fix type of HPET "timers" property 2025-03-20 12:14:45 +01:00
qdev-user.c qdev: Implement qdev_create_fake_machine() for user emulation 2025-01-09 18:16:24 +01:00
qdev.c qom: Make InterfaceInfo[] uses const 2025-04-25 17:00:41 +02:00
register.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
reset.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
resetcontainer.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
resettable.c hw/core/resettable: Remove transitional_function machinery 2024-09-13 15:31:46 +01:00
split-irq.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
stream.c hw/core/stream: Rename StreamSlave as StreamSink 2020-12-10 12:15:04 -05:00
sysbus-fdt.c vfio: Introduce new files for VFIORegion definitions and declarations 2025-04-25 09:01:37 +02:00
sysbus.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
trace-events trace-events: remove the remaining vcpu trace events 2023-06-01 11:05:05 -04:00
trace.h trace: switch position of headers to what Meson requires 2020-08-21 06:18:24 -04:00
uboot_image.h license: Update deprecated SPDX tag GPL-2.0+ to GPL-2.0-or-later 2024-09-20 10:11:59 +03:00
vm-change-state-handler.c include: Rename sysemu/ -> system/ 2024-12-20 17:44:56 +01:00
vmstate-if.c vmstate: add qom interface to get id 2020-01-06 18:41:32 +04:00