xemu/hw/misc/vmcoreinfo.c
Marc-André Lureau c3b1642b9b dump-guest-memory.py: fix "You can't do that without a process to debug"
If the script is run with a core (no running process), it produces an
error:

(gdb)  dump-guest-memory /tmp/vmcore X86_64
guest RAM blocks:
target_start     target_end       host_addr        message count
---------------- ---------------- ---------------- ------- -----
0000000000000000 00000000000a0000 00007f7935800000 added       1
00000000000a0000 00000000000b0000 00007f7934200000 added       2
00000000000c0000 00000000000ca000 00007f79358c0000 added       3
00000000000ca000 00000000000cd000 00007f79358ca000 joined      3
00000000000cd000 00000000000e8000 00007f79358cd000 joined      3
00000000000e8000 00000000000f0000 00007f79358e8000 joined      3
00000000000f0000 0000000000100000 00007f79358f0000 joined      3
0000000000100000 0000000080000000 00007f7935900000 joined      3
00000000fd000000 00000000fe000000 00007f7934200000 added       4
00000000fffc0000 0000000100000000 00007f7935600000 added       5
Python Exception <class 'gdb.error'> You can't do that without a process to debug.:
Error occurred in Python command: You can't do that without a process
to debug.

Replace the object_resolve_path_type() function call with a local
volatile variable.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
2018-01-02 14:49:54 +01:00

101 lines
2.9 KiB
C

/*
* Virtual Machine coreinfo device
*
* Copyright (C) 2017 Red Hat, Inc.
*
* Authors: Marc-André Lureau <marcandre.lureau@redhat.com>
*
* This work is licensed under the terms of the GNU GPL, version 2 or later.
* See the COPYING file in the top-level directory.
*
*/
#include "qemu/osdep.h"
#include "qapi/error.h"
#include "hw/nvram/fw_cfg.h"
#include "hw/misc/vmcoreinfo.h"
static void fw_cfg_vmci_write(void *dev, off_t offset, size_t len)
{
VMCoreInfoState *s = VMCOREINFO(dev);
s->has_vmcoreinfo = offset == 0 && len == sizeof(s->vmcoreinfo)
&& s->vmcoreinfo.guest_format != VMCOREINFO_FORMAT_NONE;
}
static void vmcoreinfo_reset(void *dev)
{
VMCoreInfoState *s = VMCOREINFO(dev);
s->has_vmcoreinfo = false;
memset(&s->vmcoreinfo, 0, sizeof(s->vmcoreinfo));
s->vmcoreinfo.host_format = cpu_to_le16(VMCOREINFO_FORMAT_ELF);
}
static void vmcoreinfo_realize(DeviceState *dev, Error **errp)
{
VMCoreInfoState *s = VMCOREINFO(dev);
FWCfgState *fw_cfg = fw_cfg_find();
/* for gdb script dump-guest-memory.py */
static VMCoreInfoState * volatile vmcoreinfo_state G_GNUC_UNUSED;
/* Given that this function is executing, there is at least one VMCOREINFO
* device. Check if there are several.
*/
if (!vmcoreinfo_find()) {
error_setg(errp, "at most one %s device is permitted",
VMCOREINFO_DEVICE);
return;
}
if (!fw_cfg || !fw_cfg->dma_enabled) {
error_setg(errp, "%s device requires fw_cfg with DMA",
VMCOREINFO_DEVICE);
return;
}
fw_cfg_add_file_callback(fw_cfg, "etc/vmcoreinfo",
NULL, fw_cfg_vmci_write, s,
&s->vmcoreinfo, sizeof(s->vmcoreinfo), false);
qemu_register_reset(vmcoreinfo_reset, dev);
vmcoreinfo_state = s;
}
static const VMStateDescription vmstate_vmcoreinfo = {
.name = "vmcoreinfo",
.version_id = 1,
.minimum_version_id = 1,
.fields = (VMStateField[]) {
VMSTATE_BOOL(has_vmcoreinfo, VMCoreInfoState),
VMSTATE_UINT16(vmcoreinfo.host_format, VMCoreInfoState),
VMSTATE_UINT16(vmcoreinfo.guest_format, VMCoreInfoState),
VMSTATE_UINT32(vmcoreinfo.size, VMCoreInfoState),
VMSTATE_UINT64(vmcoreinfo.paddr, VMCoreInfoState),
VMSTATE_END_OF_LIST()
},
};
static void vmcoreinfo_device_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
dc->vmsd = &vmstate_vmcoreinfo;
dc->realize = vmcoreinfo_realize;
dc->hotpluggable = false;
set_bit(DEVICE_CATEGORY_MISC, dc->categories);
}
static const TypeInfo vmcoreinfo_device_info = {
.name = VMCOREINFO_DEVICE,
.parent = TYPE_DEVICE,
.instance_size = sizeof(VMCoreInfoState),
.class_init = vmcoreinfo_device_class_init,
};
static void vmcoreinfo_register_types(void)
{
type_register_static(&vmcoreinfo_device_info);
}
type_init(vmcoreinfo_register_types)