From nobody Wed Nov 27 02:43:58 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701983145505750.6789116422874; Thu, 7 Dec 2023 13:05:45 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rBLXw-0002hp-ER; Thu, 07 Dec 2023 16:04:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rBLXq-0002bb-SJ for qemu-devel@nongnu.org; Thu, 07 Dec 2023 16:04:31 -0500 Received: from smtp1.lauterbach.com ([62.154.241.196]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rBLXn-0005nM-4o for qemu-devel@nongnu.org; Thu, 07 Dec 2023 16:04:30 -0500 Received: (qmail 10283 invoked by uid 484); 7 Dec 2023 21:04:07 -0000 Received: from nedpc1.intern.lauterbach.com (Authenticated_SSL:neder@[10.2.11.92]) (envelope-sender ) by smtp1.lauterbach.com (qmail-ldap-1.03) with TLS_AES_256_GCM_SHA384 encrypted SMTP for ; 7 Dec 2023 21:04:05 -0000 X-Qmail-Scanner-Diagnostics: from nedpc1.intern.lauterbach.com by smtp1.lauterbach.com (envelope-from , uid 484) with qmail-scanner-2.11 (mhr: 1.0. clamdscan: 0.99/21437. spamassassin: 3.4.0. Clear:RC:1(10.2.11.92):. Processed in 0.072318 secs); 07 Dec 2023 21:04:07 -0000 From: Nicolas Eder To: qemu-devel@nongnu.org Cc: "Nicolas Eder" , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Christian Boenig" , =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [PATCH v4 04/17] gdbstub: DebugClass added to system mode. Date: Thu, 7 Dec 2023 22:03:45 +0100 Message-Id: <20231207210358.7409-5-nicolas.eder@lauterbach.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231207210358.7409-1-nicolas.eder@lauterbach.com> References: <20231207210358.7409-1-nicolas.eder@lauterbach.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Qmail-Scanner-2.11: added fake Content-Type header Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=62.154.241.196; envelope-from=nicolas.eder@lauterbach.com; helo=smtp1.lauterbach.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1701983146799100003 Content-Type: text/plain; charset="utf-8" This class is used to abstract debug features between different debuggers --- debug/common/debug.c | 33 +++++++++++++++++++++++++++++++++ debug/common/meson.build | 1 + debug/gdbstub/system.c | 18 ++++++++++++++++++ debug/meson.build | 1 + include/hw/boards.h | 1 + include/qemu/debug.h | 20 ++++++++++++++++++++ include/qemu/typedefs.h | 2 ++ system/cpus.c | 9 ++++++++- 8 files changed, 84 insertions(+), 1 deletion(-) diff --git a/debug/common/debug.c b/debug/common/debug.c index c24aaf1202..476c969c98 100644 --- a/debug/common/debug.c +++ b/debug/common/debug.c @@ -16,3 +16,36 @@ * * SPDX-License-Identifier: LGPL-2.0+ */ + +#include "qemu/osdep.h" +#include "qemu/debug.h" +#include "qom/object_interfaces.h" + +static void debug_instance_init(Object *obj) +{ +} + +static void debug_finalize(Object *obj) +{ +} + +static void debug_class_init(ObjectClass *oc, void *data) +{ +} + +static const TypeInfo debug_info =3D { + .name =3D TYPE_DEBUG, + .parent =3D TYPE_OBJECT, + .instance_size =3D sizeof(DebugState), + .instance_init =3D debug_instance_init, + .instance_finalize =3D debug_finalize, + .class_size =3D sizeof(DebugClass), + .class_init =3D debug_class_init +}; + +static void debug_register_types(void) +{ + type_register_static(&debug_info); +} + +type_init(debug_register_types); diff --git a/debug/common/meson.build b/debug/common/meson.build index e69de29bb2..815cb6f0fc 100644 --- a/debug/common/meson.build +++ b/debug/common/meson.build @@ -0,0 +1 @@ +system_ss.add(files('debug.c')) diff --git a/debug/gdbstub/system.c b/debug/gdbstub/system.c index 83fd452800..06bc580147 100644 --- a/debug/gdbstub/system.c +++ b/debug/gdbstub/system.c @@ -14,6 +14,7 @@ #include "qapi/error.h" #include "qemu/error-report.h" #include "qemu/cutils.h" +#include "qemu/debug.h" #include "exec/gdbstub.h" #include "gdbstub/syscalls.h" #include "exec/hwaddr.h" @@ -46,6 +47,20 @@ static void reset_gdbserver_state(void) gdbserver_state.allow_stop_reply =3D false; } =20 +/** + * gdb_init_debug_class() - initialize gdb-specific DebugClass + */ +static void gdb_init_debug_class(void) +{ + Object *obj; + obj =3D object_new(TYPE_DEBUG); + DebugState *ds =3D DEBUG(obj); + DebugClass *dc =3D DEBUG_GET_CLASS(ds); + dc->set_stop_cpu =3D gdb_set_stop_cpu; + MachineState *ms =3D MACHINE(qdev_get_machine()); + ms->debug_state =3D ds; +} + /* * Return the GDB index for a given vCPU state. * @@ -405,6 +420,9 @@ int gdbserver_start(const char *device) gdbserver_system_state.mon_chr =3D mon_chr; gdb_syscall_reset(); =20 + /* create new debug object */ + gdb_init_debug_class(); + return 0; } =20 diff --git a/debug/meson.build b/debug/meson.build index a5b093f31e..f46ab14af9 100644 --- a/debug/meson.build +++ b/debug/meson.build @@ -1 +1,2 @@ +subdir('common') subdir('gdbstub') diff --git a/include/hw/boards.h b/include/hw/boards.h index da85f86efb..2e28913afc 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -400,6 +400,7 @@ struct MachineState { CpuTopology smp; struct NVDIMMState *nvdimms_state; struct NumaState *numa_state; + DebugState *debug_state; }; =20 #define DEFINE_MACHINE(namestr, machine_initfn) \ diff --git a/include/qemu/debug.h b/include/qemu/debug.h index c24aaf1202..9526f9fb48 100644 --- a/include/qemu/debug.h +++ b/include/qemu/debug.h @@ -16,3 +16,23 @@ * * SPDX-License-Identifier: LGPL-2.0+ */ + +#ifndef QEMU_DEBUG_H +#define QEMU_DEBUG_H + +#include "qom/object.h" +#include "qemu/typedefs.h" + +struct DebugClass { + ObjectClass parent_class; + void (*set_stop_cpu)(CPUState *cpu); +}; + +struct DebugState { + Object parent_obj; +}; + +#define TYPE_DEBUG "debug" +OBJECT_DECLARE_TYPE(DebugState, DebugClass, DEBUG) + +#endif /* QEMU_DEBUG_H */ diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h index 5abdbc3874..e48b544173 100644 --- a/include/qemu/typedefs.h +++ b/include/qemu/typedefs.h @@ -46,6 +46,8 @@ typedef struct CpuInfoFast CpuInfoFast; typedef struct CPUJumpCache CPUJumpCache; typedef struct CPUState CPUState; typedef struct CPUTLBEntryFull CPUTLBEntryFull; +typedef struct DebugClass DebugClass; +typedef struct DebugState DebugState; typedef struct DeviceListener DeviceListener; typedef struct DeviceState DeviceState; typedef struct DirtyBitmapSnapshot DirtyBitmapSnapshot; diff --git a/system/cpus.c b/system/cpus.c index a444a747f0..7a7fff14bc 100644 --- a/system/cpus.c +++ b/system/cpus.c @@ -25,6 +25,7 @@ #include "qemu/osdep.h" #include "monitor/monitor.h" #include "qemu/coroutine-tls.h" +#include "qemu/debug.h" #include "qapi/error.h" #include "qapi/qapi-commands-machine.h" #include "qapi/qapi-commands-misc.h" @@ -313,7 +314,13 @@ void cpu_handle_guest_debug(CPUState *cpu) cpu_single_step(cpu, 0); } } else { - gdb_set_stop_cpu(cpu); + MachineState *ms =3D MACHINE(qdev_get_machine()); + DebugState *ds =3D ms->debug_state; + DebugClass *dc =3D DEBUG_GET_CLASS(ds); + + if (dc->set_stop_cpu) { + dc->set_stop_cpu(cpu); + } qemu_system_debug_request(); cpu->stopped =3D true; } --=20 2.34.1