dump-guest-memory.py: fix "You can't do that without a process to debug"
PATCH 1/1 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 function call with a variable. I tried to use static function variables, as suggested by Laszlo in earlier reviews, but the compiler always took the chance to optimize them away.
--- scripts/dump-guest-memory.py | 3 +-- hw/misc/vmcoreinfo.c | 4 ++++ 2 files changed, 5 insertions(+), 2 deletions(-)
scripts/dump-guest-memory.py +1 -2
@@ -546,8 +546,7 @@ shape and this command should mostly work.""" return None def add_vmcoreinfo(self): - vmci = '(VMCoreInfoState *)' + \ - 'object_resolve_path_type("", "vmcoreinfo", 0)' + vmci = 'vmcoreinfo_state' if not gdb.parse_and_eval("%s" % vmci) \ or not gdb.parse_and_eval("(%s)->has_vmcoreinfo" % vmci): return
hw/misc/vmcoreinfo.c +4 -0
@@ -31,6 +31,9 @@ static void vmcoreinfo_reset(void *dev) s->vmcoreinfo.host_format =cpu_to_le16 (VMCOREINFO_FORMAT_ELF ); } +/* this variable is exported for gdb script dump-guest-memory.py */ +VMCoreInfoState *vmcoreinfo_state; +static void vmcoreinfo_realize (DeviceState *dev,Error **errp) {VMCoreInfoState *s =VMCOREINFO (dev);
@@ -56,6 +59,7 @@ static void vmcoreinfo_realize(DeviceState *dev, Error **errp) &s->vmcoreinfo, sizeof(s->vmcoreinfo), false);qemu_register_reset (vmcoreinfo_reset, dev); + vmcoreinfo_state = s; }static const VMStateDescription vmstate_vmcoreinfo = {
Signature · 1 line
2.15.1.355.g36791d7216
Quoted 17 lines · Marc-André Lureau
If the script is run with a core (no running process), it produces an error:
(gdb) dump-guest-memory
/tmp/vmcoreX86_64
guest RAM blocks:target_starttarget_endhost_addrmessage 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
Quoted 5 lines
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 function call with a variable.
Can you state, "replace the object_resolve_path_type() function call with an extern variable"?
Quoted 3 lines
I tried to use static
function variables, as suggested by Laszlo in earlier reviews, but the compiler always took the chance to optimize them away.
Did you qualify them "volatile" too?
E.g., in the vmcoreinfo_realize() function:
static VMCoreInfoState * volatile vmcoreinfo_state; ... vmcoreinfo_state = s;
(Note: it's the pointer itself that has to be volatile, not the pointed-to object.)
If you did try this, but GCC optimized it away, then that's a GCC bug. In that case I guess I can't object to the present approach any longer. Can you please confirm?
Quoted 37 lines
Signed-off-by Marc-André Lureau <[email protected]>--- scripts/dump-guest-memory.py | 3 +-- hw/misc/vmcoreinfo.c | 4 ++++ 2 files changed, 5 insertions(+), 2 deletions(-)scripts/dump-guest-memory.py +1
-2@@ -546,8 +546,7 @@ shape and this command should mostly work.""" return None def add_vmcoreinfo(self): - vmci = '(VMCoreInfoState *)' + \ - 'object_resolve_path_type("", "vmcoreinfo", 0)' + vmci = 'vmcoreinfo_state' if not gdb.parse_and_eval("%s" % vmci) \ or not gdb.parse_and_eval("(%s)->has_vmcoreinfo" % vmci): returnhw/misc/vmcoreinfo.c +3
-0@@ -31,6 +31,9 @@ static void vmcoreinfo_reset(void *dev) s->vmcoreinfo.host_format =cpu_to_le16 (VMCOREINFO_FORMAT_ELF ); } +/* this variable is exported for gdb script dump-guest-memory.py */ +VMCoreInfoState *vmcoreinfo_state; +static void vmcoreinfo_realize (DeviceState *dev,Error **errp) {VMCoreInfoState *s =VMCOREINFO (dev);
hw/misc/vmcoreinfo.c static void vmcoreinfo_realize(DeviceState *dev, Error **errp) · line 65
Quoted 7 lines
hw/misc/vmcoreinfo.c +1
-0@@ -56,6 +59,7 @@ static void vmcoreinfo_realize(DeviceState *dev, Error **errp) &s->vmcoreinfo, sizeof(s->vmcoreinfo), false);qemu_register_reset (vmcoreinfo_reset, dev); + vmcoreinfo_state = s; }static const VMStateDescription vmstate_vmcoreinfo = {
Thanks!
Laszlo
----- Original Message -----
Quoted 23 lines
On 12/12/17 17:35, Marc-André Lureau wrote:Hi
Quoted 22 lines
If the script is run with a core (no running process), it produces an error:
(gdb) dump-guest-memory
/tmp/vmcoreX86_64
guest RAM blocks:target_starttarget_endhost_addrmessage 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 5Python 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.
Quoted 4 lines
Quoted 1 line
Replace the function call with a variable.
Can you state, "replace the
object_resolve_path_type()function call with an extern variable"?
ok
Quoted 13 lines
Quoted 4 lines
I tried to use static
function variables, as suggested by Laszlo in earlier reviews, but the compiler always took the chance to optimize them away.Did you qualify them "volatile" too?
E.g., in the
vmcoreinfo_realize()function:static VMCoreInfoState * volatile vmcoreinfo_state; ... vmcoreinfo_state = s;
Quoted 7 lines
(Note: it's the pointer itself that has to be volatile, not the pointed-to object.)
If you did try this, but GCC optimized it away, then that's a GCC bug. In that case I guess I can't object to the present approach any longer. Can you please confirm?
It seems to work, but you get a gcc warning:
hw/misc/vmcoreinfo.c:38:39: warning: variable ‘vmcoreinfo_state’ set but not used [-Wunused-but-set-variable]
I'll declare it like that and send v2:
static VMCoreInfoState * volatile vmcoreinfo_state G_GNUC_UNUSED;
Quoted 50 lines
Quoted 44 lines
Signed-off-by Marc-André Lureau <[email protected]>--- scripts/dump-guest-memory.py | 3 +-- hw/misc/vmcoreinfo.c | 4 ++++ 2 files changed, 5 insertions(+), 2 deletions(-)scripts/dump-guest-memory.py +1
-2@@ -546,8 +546,7 @@ shape and this command should mostly work.""" return None def add_vmcoreinfo(self): - vmci = '(VMCoreInfoState *)' + \ - 'object_resolve_path_type("", "vmcoreinfo", 0)' + vmci = 'vmcoreinfo_state' if not gdb.parse_and_eval("%s" % vmci) \ or not gdb.parse_and_eval("(%s)->has_vmcoreinfo" % vmci): returnhw/misc/vmcoreinfo.c +4
-0@@ -31,6 +31,9 @@ static void vmcoreinfo_reset(void *dev) s->vmcoreinfo.host_format =cpu_to_le16 (VMCOREINFO_FORMAT_ELF ); } +/* this variable is exported for gdb script dump-guest-memory.py */ +VMCoreInfoState *vmcoreinfo_state; +static void vmcoreinfo_realize (DeviceState *dev,Error **errp) {VMCoreInfoState *s =VMCOREINFO (dev);@@ -56,6 +59,7 @@ static void vmcoreinfo_realize(DeviceState *dev, Error **errp) &s->vmcoreinfo,sizeof (s->vmcoreinfo), false);qemu_register_reset (vmcoreinfo_reset, dev); + vmcoreinfo_state = s; }Quoted 2 lines
static const VMStateDescription
vmstate_vmcoreinfo= {Thanks!
Laszlo
Quoted 54 lines · Marc-André Lureau
----- Original Message -----
Quoted 23 lines
On 12/12/17 17:35, Marc-André Lureau wrote:Hi
Quoted 22 lines
If the script is run with a core (no running process), it produces an error:
(gdb) dump-guest-memory
/tmp/vmcoreX86_64
guest RAM blocks:target_starttarget_endhost_addrmessage 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 5Python 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.Quoted 4 lines
Quoted 1 line
Replace the function call with a variable.
Can you state, "replace the
object_resolve_path_type()function call with an extern variable"?ok
Quoted 13 lines
Quoted 4 lines
I tried to use static
function variables, as suggested by Laszlo in earlier reviews, but the compiler always took the chance to optimize them away.Did you qualify them "volatile" too?
E.g., in the
vmcoreinfo_realize()function:static VMCoreInfoState * volatile vmcoreinfo_state; ... vmcoreinfo_state = s;Quoted 7 lines
(Note: it's the pointer itself that has to be volatile, not the pointed-to object.)
If you did try this, but GCC optimized it away, then that's a GCC bug. In that case I guess I can't object to the present approach any longer. Can you please confirm?
Quoted 6 lines
It seems to work, but you get a gcc warning:
hw/misc/vmcoreinfo.c:38:39: warning: variable ‘vmcoreinfo_state’ set but not used [-Wunused-but-set-variable]I'll declare it like that and send v2:
static VMCoreInfoState * volatilevmcoreinfo_stateG_GNUC_UNUSED;
Awesome; thank you very much!
(If "G_GNUC_UNUSED" is otherwise accepted practice in the QEMU tree; that is -- it does seem to be widely used.)
... please don't forget to update the commit message again (the variable will have block scope, static storage duration, and *no* linkage -- so it shouldn't be called "extern" like I originally suggested.)
Cheers!
Laszlo
Quoted 51 lines
Quoted 51 lines
Quoted 45 lines
Signed-off-by Marc-André Lureau <[email protected]>--- scripts/dump-guest-memory.py | 3 +-- hw/misc/vmcoreinfo.c | 4 ++++ 2 files changed, 5 insertions(+), 2 deletions(-)scripts/dump-guest-memory.py +1
-2@@ -546,8 +546,7 @@ shape and this command should mostly work.""" return None def add_vmcoreinfo(self): - vmci = '(VMCoreInfoState *)' + \ - 'object_resolve_path_type("", "vmcoreinfo", 0)' + vmci = 'vmcoreinfo_state' if not gdb.parse_and_eval("%s" % vmci) \ or not gdb.parse_and_eval("(%s)->has_vmcoreinfo" % vmci): returnhw/misc/vmcoreinfo.c +4
-0@@ -31,6 +31,9 @@ static void vmcoreinfo_reset(void *dev) s->vmcoreinfo.host_format =cpu_to_le16 (VMCOREINFO_FORMAT_ELF ); } +/* this variable is exported for gdb script dump-guest-memory.py */ +VMCoreInfoState *vmcoreinfo_state; +static void vmcoreinfo_realize (DeviceState *dev,Error **errp) {VMCoreInfoState *s =VMCOREINFO (dev);@@ -56,6 +59,7 @@ static void vmcoreinfo_realize(DeviceState *dev, Error **errp) &s->vmcoreinfo,sizeof (s->vmcoreinfo), false);qemu_register_reset (vmcoreinfo_reset, dev); + vmcoreinfo_state = s; }Quoted 2 lines
static const VMStateDescription
vmstate_vmcoreinfo= {Thanks!
Laszlo