diff options
author | Marc-André Lureau <marcandre.lureau@redhat.com> | 2016-12-07 18:39:10 +0300 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2017-01-27 18:08:00 +0100 |
commit | 777357d758d937c9dd83082c39aff9f1e53e9ba3 (patch) | |
tree | 20b236bf5acc7dfc20b4358bb8072dfe983c0e2d /gdbstub.c | |
parent | 5bf5adaeb7245d7037f29429fb231b4b602d5b50 (diff) | |
download | qemu-777357d758d937c9dd83082c39aff9f1e53e9ba3.zip qemu-777357d758d937c9dd83082c39aff9f1e53e9ba3.tar.gz qemu-777357d758d937c9dd83082c39aff9f1e53e9ba3.tar.bz2 |
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.c | 39 |
1 files changed, 32 insertions, 7 deletions
@@ -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 |