Skip to contentSkip to conversation

dump-guest-memory.py: fix "You can't do that without a process to debug"

PATCH In review Marc-André Lureau 4 participants 5 messages Dec 12, 2017 – Dec 15, 2017

lore
Share & tools
lore
#0 lore raw

PATCH v2 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 object_resolve_path_type() function call call with a local volatile variable.

---

v2:
- use a vmcoreinfo_realize() local volatile variable
- tweak commit message

scripts/dump-guest-memory.py | 3 +--

 hw/misc/vmcoreinfo.c         | 3 +++
 2 files changed, 4 insertions(+), 2 deletions(-)
scripts/dump-guest-memory.py +1 -2
index 1af26c1a45..09bec92b50 100644
@@ -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_realize::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 +3 -0
index 31db57ab44..a2805527cb 100644
@@ -35,6 +35,8 @@ 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.
@@ -56,6 +58,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
#1 lore raw
This series seems to have some coding style problems. See output below for more information:

Hi,

This series seems to have some coding style problems. See output below for more information:

Message-id: [email protected]
Subject: [Qemu-devel] [PATCH v2] dump-guest-memory.py: fix "You can't do that without a process to debug"
Type: series

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

git config --local diff.renamelimit 0
git config --local diff.renames True

commits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do

    echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
    if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
        failed=1
        echo
    fi
    n=$((n+1))

done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
t [tag update] patchew/[email protected] -> patchew/[email protected]
* [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
7c0544b1a7 dump-guest-memory.py: fix "You can't do that without a process to debug"

=== OUTPUT BEGIN ===
Checking PATCH 1/1: dump-guest-memory.py: fix "You can't do that without a process to debug"...
ERROR: Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt #46: FILE: hw/misc/vmcoreinfo.c:39:
+ static VMCoreInfoState * volatile vmcoreinfo_state G_GNUC_UNUSED;

total: 1 errors, 0 warnings, 24 lines checked

Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

=== OUTPUT END ===

Test command exited with code: 1

---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]

#2 lore raw
Quoted 52 lines · On 12/12/17 18:26, [email protected] wrote:

Hi,

This series seems to have some coding style problems. See output below for more information:

Message-id: [email protected]
Subject: [Qemu-devel] [PATCH v2] dump-guest-memory.py: fix "You can't do that without a process to debug"
Type: series

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

git config --local diff.renamelimit 0
git config --local diff.renames True

commits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do

    echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
    if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
        failed=1
        echo
    fi
    n=$((n+1))

done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
t [tag update] patchew/[email protected] -> patchew/[email protected]
* [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
7c0544b1a7 dump-guest-memory.py: fix "You can't do that without a process to debug"

=== OUTPUT BEGIN ===
Checking PATCH 1/1: dump-guest-memory.py: fix "You can't do that without a process to debug"...
ERROR: Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt #46: FILE: hw/misc/vmcoreinfo.c:39:
+ static VMCoreInfoState * volatile vmcoreinfo_state G_GNUC_UNUSED;

total: 1 errors, 0 warnings, 24 lines checked

Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

Quoted 9 lines

=== OUTPUT END ===

Test command exited with code: 1

---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]

"volatile" is required in this case; otherwise GCC would be entirely justified to eliminate the variable.

#3 lore raw
Quoted 58 lines · Laszlo Ersek
Quoted 57 lines · On 12/12/17 18:26, [email protected] wrote:

Hi,

This series seems to have some coding style problems. See output below for more information:

Message-id: [email protected]
Subject: [Qemu-devel] [PATCH v2] dump-guest-memory.py: fix "You can't do that without a process to debug"
Type: series

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

git config --local diff.renamelimit 0
git config --local diff.renames True

commits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do

    echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
    if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
        failed=1
        echo
    fi
    n=$((n+1))

done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
t [tag update] patchew/[email protected] -> patchew/[email protected]
* [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
7c0544b1a7 dump-guest-memory.py: fix "You can't do that without a process to debug"

=== OUTPUT BEGIN ===
Checking PATCH 1/1: dump-guest-memory.py: fix "You can't do that without a process to debug"...
ERROR: Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt #46: FILE: hw/misc/vmcoreinfo.c:39:
+ static VMCoreInfoState * volatile vmcoreinfo_state G_GNUC_UNUSED;

total: 1 errors, 0 warnings, 24 lines checked

Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

=== OUTPUT END ===

Test command exited with code: 1

Quoted 7 lines
Quoted 4 lines

---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]

"volatile" is required in this case; otherwise GCC would be entirely justified to eliminate the variable.

OK, maybe we should relax it to warning instead of error for volatile usages, as long as it follows a comment?

Fam

Reviewed-by on v2 1/1
#4 lore raw
In reply to Marc-André Lureau
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/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
Quoted 6 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 object_resolve_path_type() function call call with a local volatile variable.

Patch looks great and the above is fine with me too -- I just note we have "call call", which could be improved. But, I don't insist.

Thanks!
Laszlo

Quoted 48 lines

---

v2:
- use a vmcoreinfo_realize() local volatile variable
- tweak commit message

scripts/dump-guest-memory.py | 3 +--

 hw/misc/vmcoreinfo.c         | 3 +++
 2 files changed, 4 insertions(+), 2 deletions(-)
scripts/dump-guest-memory.py +1 -2
index 1af26c1a45..09bec92b50 100644
@@ -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_realize::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 +3 -0
index 31db57ab44..a2805527cb 100644
@@ -35,6 +35,8 @@ 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.
@@ -56,6 +58,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 = {