aboutsummaryrefslogtreecommitdiff
path: root/gdbstub.c
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2016-12-07 18:39:10 +0300
committerPaolo Bonzini <pbonzini@redhat.com>2017-01-27 18:08:00 +0100
commit777357d758d937c9dd83082c39aff9f1e53e9ba3 (patch)
tree20b236bf5acc7dfc20b4358bb8072dfe983c0e2d /gdbstub.c
parent5bf5adaeb7245d7037f29429fb231b4b602d5b50 (diff)
chardev: qom-ify
Turn Chardev into Object. qemu_chr_alloc() is replaced by the qemu_chardev_new() constructor. It will call qemu_char_open() to open/intialize the chardev with the ChardevCommon *backend settings. The CharDriver::create() callback is turned into a ChardevClass::open() which is called from the newly introduced qemu_chardev_open(). "chardev-gdb" and "chardev-hci" are internal chardev and aren't creatable directly with -chardev. Use a new internal flag to disable them. We may want to use TYPE_USER_CREATABLE interface instead, or perhaps allow -chardev usage. Although in general we keep typename and macros private, unless the type is being used by some other file, in this patch, all types and common helper macros for qemu-char.c are in char.h. This is to help transition now (some types must be declared early, while some aren't shared) and when splitting in several units. This is to be improved later. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'gdbstub.c')
-rw-r--r--gdbstub.c39
1 files changed, 32 insertions, 7 deletions
diff --git a/gdbstub.c b/gdbstub.c
index 9a934a028f..755a8e378d 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -1725,18 +1725,35 @@ static void gdb_sigterm_handler(int signal)
}
#endif
+static void gdb_monitor_open(Chardev *chr, ChardevBackend *backend,
+ bool *be_opened, Error **errp)
+{
+ *be_opened = false;
+}
+
+static void char_gdb_class_init(ObjectClass *oc, void *data)
+{
+ ChardevClass *cc = CHARDEV_CLASS(oc);
+
+ cc->internal = true;
+ cc->open = gdb_monitor_open;
+ cc->chr_write = gdb_monitor_write;
+}
+
+#define TYPE_CHARDEV_GDB "chardev-gdb"
+
+static const TypeInfo char_gdb_type_info = {
+ .name = TYPE_CHARDEV_GDB,
+ .parent = TYPE_CHARDEV,
+ .class_init = char_gdb_class_init,
+};
+
int gdbserver_start(const char *device)
{
GDBState *s;
char gdbstub_device_name[128];
Chardev *chr = NULL;
Chardev *mon_chr;
- ChardevCommon common = { 0 };
- static const CharDriver driver = {
- .instance_size = sizeof(Chardev),
- .kind = -1,
- .chr_write = gdb_monitor_write,
- };
if (!first_cpu) {
error_report("gdbstub: meaningless to attach gdb to a "
@@ -1775,7 +1792,8 @@ int gdbserver_start(const char *device)
qemu_add_vm_change_state_handler(gdb_vm_state_change, NULL);
/* Initialize a monitor terminal for gdb */
- mon_chr = qemu_chr_alloc(&driver, &common, &error_abort);
+ mon_chr = qemu_chardev_new(NULL, TYPE_CHARDEV_GDB,
+ NULL, &error_abort);
monitor_init(mon_chr, 0);
} else {
if (qemu_chr_fe_get_driver(&s->chr)) {
@@ -1798,4 +1816,11 @@ int gdbserver_start(const char *device)
return 0;
}
+
+static void register_types(void)
+{
+ type_register_static(&char_gdb_type_info);
+}
+
+type_init(register_types);
#endif