Skip to contentSkip to conversation

scripts/dump-guest-memory.py: fix int128_get64 on recent gcc

PATCH In review Marc-André Lureau 2 participants 2 messages Mar 10, 2017 – Mar 11, 2017

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 scripts/dump-guest-memory.py: fix int128_get64 on recent gcc

The Int128 is no longer a struct, reaching a python exception:
Python Exception <class 'gdb.error'> Attempt to extract a component of a value that is not a (null).:

Replace struct access with a cast to uint64[] instead.

Fixes:
https://bugzilla.redhat.com/show_bug.cgi?id=1427466

---
v2:
- try with old struct hi/lo fields first for compatibility
- handle endianess in uint64[] case

Note: untested on other arch than x86_64

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

 1 file changed, 12 insertions(+), 2 deletions(-)
scripts/dump-guest-memory.py +12 -2
index 9956fc036c..f7c6635f15 100644
@@ -314,8 +314,18 @@ def get_arch_phdr(endianness, elfclass):
 def int128_get64(val):
     """Returns low 64bit part of Int128 struct."""
 
-    assert val["hi"] == 0
-    return val["lo"]
+    try:
+        assert val["hi"] == 0
+        return val["lo"]
+    except gdb.error:
+        u64t = gdb.lookup_type('uint64_t').array(2)
+        u64 = val.cast(u64t)
+        if sys.byteorder == 'little':
+            assert u64[1] == 0
+            return u64[0]
+        else:
+            assert u64[0] == 0
+            return u64[1]
 
 
 def qlist_foreach(head, field_str):
Signature · 1 line
2.12.0.rc2.3.gc93709801
Reviewed-by on v2 1/1
#1 lore raw
Quoted 35 lines · Marc-André Lureau

The Int128 is no longer a struct, reaching a python exception:
Python Exception <class 'gdb.error'> Attempt to extract a component of a value that is not a (null).:

Replace struct access with a cast to uint64[] instead.

Fixes:
https://bugzilla.redhat.com/show_bug.cgi?id=1427466

---
v2:
- try with old struct hi/lo fields first for compatibility
- handle endianess in uint64[] case

Note: untested on other arch than x86_64

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

 1 file changed, 12 insertions(+), 2 deletions(-)
scripts/dump-guest-memory.py +5 -2
index 9956fc036c..f7c6635f15 100644
@@ -314,8 +314,18 @@ def get_arch_phdr(endianness, elfclass):
 def int128_get64(val):
     """Returns low 64bit part of Int128 struct."""
 
-    assert val["hi"] == 0
-    return val["lo"]
+    try:
+        assert val["hi"] == 0
+        return val["lo"]
+    except gdb.error:
+        u64t = gdb.lookup_type('uint64_t').array(2)

scripts/dump-guest-memory.py def get_arch_phdr(endianness, elfclass): · line 331

Quoted 10 lines
scripts/dump-guest-memory.py +7 -0
+        u64 = val.cast(u64t)
+        if sys.byteorder == 'little':
+            assert u64[1] == 0
+            return u64[0]
+        else:
+            assert u64[0] == 0
+            return u64[1]
 
 
 def qlist_foreach(head, field_str):